/*
 * 文件名：CarInAndOutServiceImpl.java	 
 * 时     间：下午10:11:54
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cloud.entity.ResultVo;
import com.cloud.otherThreads.UploadReportCarInfoRunble;
import com.cloud.threads.UploadCarInInfoRunble;
import com.cz073586.message.websocket356.push.PushManager;
import com.cz073586.message.websocket356.transfer.TransferVo;
import com.cz073586.tools.date.DateFormatString;
import com.cz073586.tools.date.DateTools;
import com.cz073586.tools.http.HttpManagerUtil;
import com.cz073586.tools.util.JsonUtil;
import com.cz073586.tools.util.Log4jUtil;
import com.cz073586.tools.util.ThreadPoolUtil;
import com.index.entity.Page;
import com.local.common.CommonContains;
import com.local.common.GateWayConstans;
import com.local.common.LogInfoConstan;
import com.local.common.MessageContains;
import com.local.common.PayTypeConstans;
import com.local.controller.index.LocalIndexCarInAndOutExController;
import com.local.dao.hismappers.CarParkInCopyMapper;
import com.local.dao.hismappers.CarParkOutCopyMapper;
import com.local.dao.hismappers.LocalPayBillMapper;
import com.local.dao.mapers.CarParkInMapper;
import com.local.dao.mapers.CarParkOutMapper;
import com.local.dao.mapers.IntegrationMapper;
import com.local.dao.mapers.LocalCarInRepertoryMapper;
import com.local.dao.mapers.LocalCarTypeMapper;
import com.local.dao.mapers.LocalChargeBytimeCopyMapper;
import com.local.dao.mapers.LocalChargeBytimeMapper;
import com.local.dao.mapers.LocalChargeBytimeTypeMapper;
import com.local.dao.mapers.LocalEquipmentMapper;
import com.local.dao.mapers.LocalScreenMapper;
import com.local.dao.mapers.ParklotNumberMapper;
import com.local.entity.ex.CarParkInCopyEx;
import com.local.entity.ex.CarParkInEx;
import com.local.entity.ex.CarParkOutCopyEx;
import com.local.entity.ex.CarParkOutEx;
import com.local.entity.vo.CarBillVo;
import com.local.entity.vo.CarInAndOutPhotoVo;
import com.local.entity.vo.CarInManualOpenVo;
import com.local.entity.vo.CarOutInfoVo;
import com.local.entity.vo.CarOutPayBillVo;
import com.local.entity.vo.CarParkInOverVo;
import com.local.entity.vo.ParklotVo;
import com.local.entity.vo.ParkwellPayBillVo;
import com.local.entity.vo.ReportCarInfoVo;
import com.local.entity.webpush.CarInPushVo;
import com.local.manager.cfgManager.BlackAndWhiteCfgManager;
import com.local.manager.cfgManager.CloudConfigManager;
import com.local.manager.cfgManager.ConfigManager;
import com.local.manager.cfgManager.reportConfigManager;
import com.local.manager.dic.DicMananger;
import com.local.manager.locks.RecordLockManager;
import com.local.manager.push.PushCarInBillInfoRunble;
import com.local.manager.thread.OpenCateThreadNew;
import com.local.manager.thread.UpdateThread;
import com.local.model.AdminCarInBill;
import com.local.model.CarParkIn;
import com.local.model.CarParkInCopy;
import com.local.model.CarParkInCopyExample;
import com.local.model.CarParkInExample;
import com.local.model.CarParkOut;
import com.local.model.CarParkOutCopy;
import com.local.model.CarParkOutCopyExample;
import com.local.model.CarParkOutExample;
import com.local.model.Crossing;
import com.local.model.FreeCar;
import com.local.model.Integration;
import com.local.model.IntegrationExample;
import com.local.model.LocalBlackList;
import com.local.model.LocalCarInRepertory;
import com.local.model.LocalCarInRepertoryExample;
import com.local.model.LocalCarType;
import com.local.model.LocalChargeBytime;
import com.local.model.LocalChargeBytimeCopy;
import com.local.model.LocalChargeBytimeExample;
import com.local.model.LocalChargeBytimeType;
import com.local.model.LocalChargeBytimeTypeExample;
import com.local.model.LocalEquipment;
import com.local.model.LocalEquipmentExample;
import com.local.model.LocalMember;
import com.local.model.LocalPayBill;
import com.local.model.LocalStation;
import com.local.model.LocalTemporaryCheck;
import com.local.model.Log;
import com.local.model.ParklotNumber;
import com.local.model.Screen;
import com.local.page.CarInAndOutPageInfo;
import com.local.service.face.CarInAndOutService;
import com.local.service.face.CrossingService;
import com.local.service.face.FreeCarService;
import com.local.service.face.LocalBizUpdateService;
import com.local.service.face.LocalBlackListService;
import com.local.service.face.LocalChargeByTimeCopyService;
import com.local.service.face.LocalChargeByTimeService;
import com.local.service.face.LocalChargeByTimeTypeService;
import com.local.service.face.LocalParkSpaceCheckService;
import com.local.service.face.LocalTemporaryCheckService;
import com.local.service.face.LocalVersionService;
import com.local.service.face.LogService;
import com.local.service.face.ParkwellMemberService;
import com.local.service.face.ParkwellPayBillService;
import com.local.util.HttpClientUtil;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.entity.PageInfo;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.BeanUtil;
import com.qianhai.common.utils.Tools;
import com.qianhai.common.utils.UUIDGenerateUtil;
import com.zbc.lucene.util.FieldEnum;
import com.zbc.lucene.util.IndexUtil;
import com.zbc.lucene.util.LuceneConstants;
import com.zbc.lucene.util.SearchUtil;

/**
 * 类描述:这里是类描述
 * 
 * @ClassName: CarInAndOutServiceImpl
 * @author Administrator
 * @date 2015年4月2日 下午10:11:54
 */
@Service
public class CarInAndOutServiceImpl extends
		BaseServiceImpl<Object, Object, String> implements CarInAndOutService
{
	@Autowired
	private CarParkInMapper carInMapper;
	
	@Autowired
	private CarParkInCopyMapper carParkInCopyMapper;
	
	@Autowired
	private CarParkOutCopyMapper carOutCopyMapper;
	
	@Autowired
	private CarParkOutMapper carOutMapper;
	
	@Autowired
	private LocalVersionService localVersionServiceImpl;
	
	@Autowired
	private LocalBizUpdateService localBizUpdateService;
	
	@Autowired
	private LocalBlackListService localBlackListService; // 黑白名单
	
	@Autowired
	private ParkwellMemberService parkwellMemberService; // 会员信息
	
	@Autowired
	private FreeCarService freeCarService; // 免费卡
	
	@Autowired
	private LocalPayBillMapper localPayBillMapper;
	
	@Autowired
	private LogService logService;
	
	@Autowired
	private CrossingService crossionService;
	
	@Autowired
	private LocalTemporaryCheckService localTemporaryCheckService;
	@Autowired
	private ParklotNumberMapper lotNumberMapper;
	@Autowired
	private IntegrationMapper interationMapper;
	@Autowired
	private LocalChargeByTimeCopyService localChargeByTimeCopyService;
	@Autowired
	private CrossingService crossinService;
	@Autowired
	private LogService logServier;
	
	@Autowired
	private LocalChargeBytimeTypeMapper billTypeMapper;
	
	@Autowired
	private LocalChargeBytimeCopyMapper chargeBytimeCopyMapper;
	
	@Autowired
	private LocalEquipmentMapper localEquipmentMapper;
	@Autowired
	private LocalParkSpaceCheckService localParkSpaceCheckService;
	
	@Autowired
	private LocalChargeBytimeMapper localChargeBytimeMapper;
	
	@Autowired
	private LocalCarInRepertoryMapper localCarInRepertoryMapper;
	
	@Autowired
	private LocalChargeByTimeTypeService localChargeByTimeTypeService;
	
	@Autowired
	private LocalScreenMapper localScreenMapper;
	
	@Autowired
	private ParkwellPayBillService payBilllService;
	
	@Autowired
	private LocalCarTypeMapper catTypeMapper;
	
	@Autowired
	private LocalChargeByTimeService billRuleService;
	
	private Log4jUtil log = Log4jUtil
			.getLog4j(LocalIndexCarInAndOutExController.class);

	@Override
	public CarParkInOverVo findOverAddCarParkInBill(CarParkIn carParkIn)
			throws BaseException
	{
		// TODO Auto-generated method stub
		CarParkInOverVo vo = new CarParkInOverVo();
		try
		{
			boolean ff = true;
			// 判断开闸标记，标记为真,所有CarParkInOverVo需要填充的数据，在线程CarParkInLocalThread中填充
			vo.setOpen(ff);// 默认开闸
			carParkIn.setStatus(1);
			carParkIn.setOriginalCarNo(carParkIn.getCarNo());// 保留相机原始识别车牌信息
			
			if (Tools.isEmpty(carParkIn.getCarNo()))
			{
				carParkIn.setCarNo("无效车牌");
			}
			
			if (Tools.isEmpty(carParkIn.getExchangeUuid()))
			{
				throw new BaseException("90000-00001-00001");
			}
			
			if (Tools.isEmpty(carParkIn.getEquipment()))
			{
				throw new BaseException("90000-00001-00002");
			}
			
			// 检查出入口设置是否正确.//检查控制汇总开关 2016-71-24
			List<Crossing> crossList = crossinService
					.queryCrossingByEquimentNo(carParkIn.getEquipment());
			if (Tools.isEmpty(crossList) || crossList.isEmpty())
			{
				throw new BaseException("50000-00001-00046");
			}
			
			if (crossList.size() > 0)
			{
				vo.setRoadNmae(crossList.get(0).getName());
				vo.setRoadUuid(crossList.get(0).getUuid());
				// 检查控制汇总开关 2016-71-24
				if (!Tools.isEmpty(crossList.get(0).getProcessId()))
				{
					vo.setCollect(true);
					vo.setCollectRoadUuid(crossList.get(0).getProcessId());
					vo.setCollectCtrEqNo(crossList.get(0)
							.getEquipmentViewStream());
				}
				// 检查控制汇总开关 2016-71-24
			}
			// 检查控制汇总开关 2016-71-24
			
			carParkIn.setUuid(UUIDGenerateUtil.generate());
			carParkIn.setCreateTime(new Date());
			carParkIn.setOpenTime(DateTools.dateToString(
					carParkIn.getCreateTime(),
					DateFormatString.yyyy_MM_dd_HH_mm_ss_H));
			vo.setCarparkIn(carParkIn);
			// 封装前端推送数据
			CarInPushVo pushCarInVo = new CarInPushVo();
			pushCarInVo.setCarNo(carParkIn.getCarNo());
			pushCarInVo.setEuqmentNo(carParkIn.getEquipment());
			pushCarInVo.setIsOpenGate("2");
			pushCarInVo.setCarInUuid(carParkIn.getUuid());
			vo.setCarInPushVo(pushCarInVo);
			
			if (carParkIn.getCarNo().trim().equals("无效车牌"))
			{
				carParkIn.setStatus(2);
				vo.setOpen(false);
				return vo;
			}
			
			// 判断进场车辆是否重复进场时是否覆盖(默认覆盖),如需要弹框则闸机不开.
			vo.setReptCarNoWhenCarInCrt(true);// 默认覆盖重复数据
			if (!DicMananger.instance().isReptCarNoWhenCarIn())// 开关打开
			{
				vo.setReptCarNoWhenCarInCrt(false);// 标记开关打开
				// 重复时需要提示框
				LocalCarInRepertoryExample resutEx = new LocalCarInRepertoryExample();
				resutEx.or().andCarNoEqualTo(carParkIn.getCarNo().trim());
				List<LocalCarInRepertory> resutList = localCarInRepertoryMapper
						.selectByCondition(resutEx);
				if (!Tools.isEmpty(resutList) && !resutList.isEmpty())
				{
					vo.setOpen(false);
					carParkIn.setStatus(2);
					vo.setReptCaoNo(true);// 已经重复
					pushCarInVo.setReptCarInuuid(resutList.get(0)
							.getCarInUuid());
					return vo;
				}
			} // end if
			
			// 获取 临停车辆入场权限 1:默认开闸 2:开启临停检测(默认不开闸)
			/*
			 * LocalTemporaryCheck ltc = localTemporaryCheckService
			 * .queryLocalTemporaryCheck();
			 */
			// ###
			Boolean flag = localTemporaryCheckService
					.queryLocalTemporaryCheckStatus();
			if (!flag)
			{
				vo.setOpen(false);
				// 判断是否会员，免费车，警车，军车等....
				LocalChargeBytimeType ltc = this.makeCarNoType(carParkIn);
				vo.setCarNoType(!Tools.isEmpty(ltc) ? ltc.getName()
						: MessageContains.TEMP_CAR_TYPE);
				// 判断类型，是否临停可以进入 true 可以
				ff = this.panCarNoType(vo.getCarNoType());
				vo.setOpen(ff);
				if (!ff)
				{
					// 不开闸记录为待进场
					carParkIn.setStatus(2);
				}
				return vo;
			}
			
			// 进场控制(车位满时)
			flag = localParkSpaceCheckService.queryLocalParkSpaceCheckStatus();
			// LocalParkSpaceCheck lpsc =
			// localParkSpaceCheckService.queryLocalParkSpaceCheck();
			if (!flag)
			{
				// 判断是否会员，免费车，警车，军车等....
				if (Tools.isEmpty(vo.getCarNoType()))
				{
					LocalChargeBytimeType ltc = this.makeCarNoType(carParkIn);
					vo.setCarNoType(!Tools.isEmpty(ltc) ? ltc.getName()
							: MessageContains.TEMP_CAR_TYPE);
				}
				// 进场控制（车位数已满时，临时车是否能进入）
				ff = this.localParkSpaceFlag(vo.getCarNoType());
				vo.setOpen(ff);
				if (!ff)
				{
					// 不开闸记录为待进场
					carParkIn.setStatus(2);
				}
				return vo;
			}
			
			return vo;
		} catch (Throwable e)
		{
			log.error("findOverAddCarParkInBill", e);
			carParkIn.setOpenMode(GateWayConstans.EXCEPTION);
			throw new BaseException(e.getMessage());
		} finally
		{
			log.debug("------------------进场识别完毕-------------------");
			// 检查控制汇总开关 2016-71-24
			if (vo.isCollect() && vo.isOpen())
			{
				// 汇总开闸
				OpenCateThreadNew openCateRunble = new OpenCateThreadNew(
						crossinService, vo.getCollectRoadUuid());
				ThreadPoolUtil.instance().execute(openCateRunble);
			}
			// 检查控制汇总开关 2016-71-24
			
			// 标记未开闸状态 2016-8-9
			if (!vo.isOpen())
			{
				carParkIn.setOpenMode(GateWayConstans.UNOPENED);
			}// 标记未开闸状态 2016-8-9
		}
	}
	
	@Override
	public LocalChargeBytimeType makeCarNoType(CarParkIn carParkIn)
	{
		LocalChargeBytimeType ltc = null;
		Map<String, Object> map = this.getIdentityTypeByCarNo(carParkIn
				.getCarNo());
		String carNoType = (String) map.get("carNoType");
		if (carNoType.equalsIgnoreCase(MessageContains.TEMP_CAR_TYPE)
				&& !Tools.isEmpty(carParkIn.getBrand()))
		{
			ltc = this.getFirCarTypeNo(carParkIn.getBrand());
			if (Tools.isEmpty(ltc))
			{
				ltc = new LocalChargeBytimeType();
				ltc.setName(MessageContains.TEMP_CAR_TYPE);
				ltc.setType("102");
			}
		}
		// 会员
		if (carNoType.equalsIgnoreCase(MessageContains.MEMBER_CAR_TYPE))
		{
			ltc = new LocalChargeBytimeType();
			Date expireTime = (Date) map.get("expireTime");
			Date startTime = (Date) map.get("startTime");
			ltc.setName("会员");
			ltc.setType("100");
			ltc.setExpireTime(expireTime);
			ltc.setStartTime(startTime);
		}
		// 免费车
		if (carNoType.equalsIgnoreCase(MessageContains.FREE_CAR_TYPE))
		{
			Date expireTime = (Date) map.get("expireTime");
			ltc = new LocalChargeBytimeType();
			ltc.setName("免费车");
			ltc.setType("101");
			ltc.setExpireTime(expireTime);
		}
		return ltc;
	}
	
	public boolean panCarNoType(String carNoType)
	{
		Boolean flag = false;
		try
		{
			LocalChargeBytimeTypeExample condtion = new LocalChargeBytimeTypeExample();
			condtion.or().andAttr1EqualTo("1");
			List<LocalChargeBytimeType> list = localChargeByTimeTypeService
					.selectByCondition(condtion);
			if (!Tools.isEmpty(list))
			{
				for (LocalChargeBytimeType lb : list)
				{
					if (lb.getName().equalsIgnoreCase(
							!Tools.isEmpty(carNoType) ? carNoType
									: MessageContains.TEMP_CAR_TYPE))
					{
						flag = true;
					}
					if (flag)
					{
						break;
					}
				}
			}
		} catch (Exception e)
		{
			// TODO: handle exception
			return true;
		}
		return flag;
	}
	
	@Override
	public boolean addCarParkInBill(CarParkIn carParkIn) throws BaseException
	{
		try
		{
			if (Tools.isEmpty(carParkIn.getCarNo()))
			{
				carParkIn.setCarNo("无效车牌");
			}
			
			if (Tools.isEmpty(carParkIn.getExchangeUuid()))
			{
				throw new BaseException("90000-00001-00001");
			}
			
			if (Tools.isEmpty(carParkIn.getEquipment()))
			{
				throw new BaseException("90000-00001-00002");
			}
			
			// 判断相机传送过来的数据是否有路口信息，防止伪数据
			List<Crossing> crossList = crossionService
					.queryCrossingByEquimentNo(carParkIn.getEquipment());
			
			if (Tools.isEmpty(crossList) || crossList.isEmpty())
			{
				throw new BaseException("50000-00001-00046");
			}
			
			// 判断重复数据
			CarParkInExample carInRIdEX = new CarParkInExample();
			carInRIdEX.or().andRecordIdEqualTo(carParkIn.getRecordId().trim());
			List<CarParkIn> resultList = carInMapper
					.selectByCondition(carInRIdEX);
			if (!Tools.isEmpty(resultList) && !resultList.isEmpty())
			{
				return false;
			}
			
			CarInPushVo pushCarInVo = new CarInPushVo();
			pushCarInVo.setCarNo(carParkIn.getCarNo());
			pushCarInVo.setEuqmentNo(carParkIn.getEquipment());
			
			// 获取 临停车辆入场权限 1:默认开闸 2:开启临停检测(默认不开闸)
			LocalTemporaryCheck ltc = localTemporaryCheckService
					.queryLocalTemporaryCheck();
			
			if (!Tools.isEmpty(ltc))
			{
				pushCarInVo.setIsOpenGate(ltc.getType());
			}
			
			// 设置车辆类型
			Map<String, Object> map = this.getIdentityTypeByCarNo(carParkIn
					.getCarNo());
			String carNoType = (String) map.get("carNoType");
			pushCarInVo.setCarNoTye(carNoType);
			
			carParkIn.setUuid(UUIDGenerateUtil.generate());
			carParkIn.setCreateTime(new Date());
			carParkIn.setOpenTime(DateTools.dateToString(
					carParkIn.getCreateTime(),
					DateFormatString.yyyy_MM_dd_HH_mm_ss_H));
			
			// 进场控制（车位数已满时，临时车是否能进入）
			boolean spaceflag = this.localParkSpaceFlag(pushCarInVo
					.getCarNoTye());
			if (spaceflag)
			{
				pushCarInVo.setIsOpenGate("1");
			} else
			{
				pushCarInVo.setIsOpenGate("2");
			}
			
			// 默认开闸 1 可以开闸 2 不可以开闸
			carParkIn.setStatus(1);
			
			// 设置默认不开闸时，会员白名单可以进入
			if (pushCarInVo.getIsOpenGate().equals("2")
					&& !pushCarInVo.getCarNoTye().equals(
							PayTypeConstans.MENMBER_TYPE)
					&& !pushCarInVo.getCarNoTye().equals("白名单"))
			{
				carParkIn.setStatus(2);
			} else
			{
				// 会员可以可以进场标记
				pushCarInVo.setIsOpenGate("1");
			}
			
			// 2016-2-27 如果为无效车牌则用户可以修改车牌,弹出框
			if (carParkIn.getCarNo().trim().equals("无效车牌"))
			{
				carParkIn.setStatus(2);
				pushCarInVo.setIsOpenGate("2");
			}
			// 2016-27
			
			pushCarInVo.setCarInUuid(carParkIn.getUuid());
			carInMapper.insertSelective(carParkIn);
			
			/*
			 * //添加进场副本 CarParkInCopy carParkInCopy=returnCarInCopy(carParkIn);
			 * if(!Tools.isEmpty(carParkInCopy)){
			 * carParkInCopyMapper.insertSelective(carParkInCopy); }
			 */
			
			// 推送前端页面
			PushCarInBillInfoRunble carInToWeb = new PushCarInBillInfoRunble(
					crossionService, pushCarInVo);
			ThreadPoolUtil.instance().execute(carInToWeb);
			
			// 删除多余已入场多余数据
			if (carParkIn.getStatus() == 1
					&& !Tools.isEmpty(carParkIn.getUuid())
					&& !carParkIn.getCarNo().equals("")
					&& !carParkIn.getCarNo().equalsIgnoreCase("无效车牌"))
			{
				CarParkInExample inEx = new CarParkInExample();
				inEx.or().andUuidNotEqualTo(carParkIn.getUuid())
						.andStatusEqualTo(1)
						.andCarNoEqualTo(carParkIn.getCarNo());
				carInMapper.deleteByCondition(inEx);
			}
			
			// 2015-12-15 如果重复车牌已经在出场纪录下,则更新出场纪录的进场数据
			CarParkOut carOut = carOutMapper.selectCarNo(carParkIn.getCarNo());
			if (!Tools.isEmpty(carOut))
			{
				carOut.setCarInUuid(carParkIn.getUuid());
				carOutMapper.updateByPrimaryKey(carOut);
			}
			// 2015-12-15 end
			
			if (carParkIn.getStatus() == 2)
			{
				return false;
			}
			return true;
			
		} catch (Throwable e)
		{
			throw new BaseException(e.getMessage());
		}
		
	}
	
	public CarParkInCopy returnCarInCopy(CarParkIn carParkIn)
	{
		CarParkInCopy carParkInCopy = new CarParkInCopy();
		if (Tools.isEmpty(carParkIn))
		{
			return null;
		}
		if (Tools.isEmpty(carParkIn.getUuid()))
		{
			carParkInCopy.setUuid(UUIDGenerateUtil.generate());
		}
		if (!Tools.isEmpty(carParkIn.getUuid()))
		{
			carParkInCopy.setUuid(carParkIn.getUuid());
		}
		if (!Tools.isEmpty(carParkIn.getCarNo()))
		{
			carParkInCopy.setCarNo(carParkIn.getCarNo());
		}
		if (!Tools.isEmpty(carParkIn.getCreateTime()))
		{
			carParkInCopy.setCreateTime(carParkIn.getCreateTime());
		}
		if (!Tools.isEmpty(carParkIn.getPic1()))
		{
			carParkInCopy.setPic1(carParkIn.getPic1());
		}
		if (!Tools.isEmpty(carParkIn.getPic2()))
		{
			carParkInCopy.setPic2(carParkIn.getPic2());
		}
		if (!Tools.isEmpty(carParkIn.getExchangeUuid()))
		{
			carParkInCopy.setExchangeUuid(carParkIn.getExchangeUuid());
		}
		if (!Tools.isEmpty(carParkIn.getEquipment()))
		{
			carParkInCopy.setEquipment(carParkIn.getEquipment());
		}
		if (!Tools.isEmpty(carParkIn.getOpenTime()))
		{
			carParkInCopy.setOpenTime(carParkIn.getOpenTime());
		}
		if (!Tools.isEmpty(carParkIn.getRecordId()))
		{
			carParkInCopy.setRecordId(carParkIn.getRecordId());
		}
		if (!Tools.isEmpty(carParkIn.getStatus()))
		{
			carParkInCopy.setStatus(carParkIn.getStatus());
		}
		return carParkInCopy;
	}
	
	@Override
	public Integer addCarParkOutBill(CarParkOut carParkOut)
			throws BaseException
	{
		try
		{
			if (Tools.isEmpty(carParkOut.getCarNo()))
			{
				throw new BaseException("90000-00001-00003");
			}
			
			if (Tools.isEmpty(carParkOut.getExchangeUuid()))
			{
				throw new BaseException("90000-00001-00001");
			}
			
			if (Tools.isEmpty(carParkOut.getEquipment()))
			{
				throw new BaseException("90000-00001-00002");
			}
			
			if (Tools.isEmpty(carParkOut.getOpenTime()))
			{
				throw new BaseException("90000-00001-00005");
			}
			
			// carParkOut.setUuid(UUIDGenerateUtil.generate());
			// carParkOut.setCreateTime(new Date());
			
			carParkOut.setOpenTime(DateTools.dateToString(new Date(),
					DateFormatString.yyyy_MM_dd_HH_mm_ss_H));
			carParkOut.setStatus(0);// 正常出场
			
			// 更新进场为正常出场
			if (!Tools.isEmpty(carParkOut.getCarInUuid()))
			{
				CarParkIn carInInfo = carInMapper.selectByPrimaryKey(carParkOut
						.getCarInUuid());
				if (!Tools.isEmpty(carInInfo))
				{
					carInInfo.setStatus(0);
					carInMapper.updateByPrimaryKeySelective(carInInfo);
				}
			}
			
			// if (CloudConfigManager.instance().isOpen())
			// {
			// UpDateCarOutInfoRunble upload = new UpDateCarOutInfoRunble(
			// carParkOut, logService);
			// ThreadPoolUtil.instance().execute(upload);
			// }
			
			return carOutMapper.updateByPrimaryKeySelective(carParkOut);
		} catch (Throwable e)
		{
			throw new BaseException(e.getMessage());
		}
		
	}
	
	@Override
	public void queryCarInByPage(CarInAndOutPageInfo<CarParkIn> page)
	{
		List<CarParkIn> dataList = carInMapper.queryByPage(page);
		// page.setData(dataList);
		
		List<CarParkIn> roList = new ArrayList<CarParkIn>();
		page.setData(roList);
		for (CarParkIn carIn : dataList)
		{
			CarParkInEx ex = new CarParkInEx();
			BeanUtil.copyProperties(ex, carIn);
			List<Crossing> list = crossionService
					.queryCrossingByEquimentNo(carIn.getEquipment());
			if (!Tools.isEmpty(list) && !list.isEmpty())
			{
				ex.setRoadName(list.get(0).getName());
				ex.setRoadUuid(list.get(0).getUuid());
			}
			
			// 收费类型
			if (!Tools.isEmpty(carIn.getBrand()))
			{
				LocalChargeBytime rule = billRuleService.findByBrandId(carIn
						.getBrand());
				ex.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3() : "未知");
				
			}
			
			// 车型,大车小车
			if (!Tools.isEmpty(carIn.getType()))
			{
				
				LocalCarType typeInfo = catTypeMapper.selectByPrimaryKey(carIn
						.getCarType());
				if (!Tools.isEmpty(typeInfo))
				{
					ex.setCarTypeName(typeInfo.getCartypeName());
				}
			}
			
			roList.add(ex);
		}
		Integer pageNumber = carInMapper.countAllByPage(page);
		page.setTotalRecords(pageNumber);
		
	}
	
	@Override
	public void queryCarOutByPage(CarInAndOutPageInfo<CarParkOut> page)
	{
		List<CarParkOut> dataList = carOutMapper.queryByPage(page);
		// page.setData(dataList);
		List<CarParkOut> listCarOutEx = new ArrayList<CarParkOut>();
		page.setData(listCarOutEx);
		
		for (CarParkOut carOut : dataList) // 获取进场信息
		{
			CarParkOutEx ex = new CarParkOutEx();
			BeanUtil.copyProperties(ex, carOut);
			listCarOutEx.add(ex);
			
			// 车辆类型，大车小车
			if (!Tools.isEmpty(carOut.getCarType()))
			{
				
				LocalCarType typeInfo = catTypeMapper.selectByPrimaryKey(carOut
						.getType());
				if (!Tools.isEmpty(typeInfo))
				{
					ex.setCarTypeName(typeInfo.getCartypeName());
				}
			}
			
			// 收费类型
			if (!Tools.isEmpty(carOut.getBrand()))
			{
				LocalChargeBytime rule = billRuleService.findByBrandId(carOut
						.getBrand());
				ex.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3() : "未知");
			}
			
			if (!Tools.isEmpty(carOut.getCarInUuid()))
			{
				CarParkInCopy carParkInCopy = carParkInCopyMapper
						.selectByPrimaryKey(carOut.getCarInUuid());
				if (!Tools.isEmpty(carParkInCopy))
				{
					ex.setStayTime(carOut.getCreateTime().getTime()
							- carParkInCopy.getCreateTime().getTime());
				}
				List<LocalPayBill> localPayBills = localPayBillMapper
						.queryAllBill(carOut.getCarInUuid());
				Double totalPrice = 0.0;
				for (LocalPayBill localPayBill : localPayBills)
				{
					totalPrice += localPayBill.getPrice();
				}
				ex.setTotalMoney(!Tools.isEmpty(totalPrice) ? totalPrice : 0d);
				
				CarParkIn carInfo = carInMapper.selectByPrimaryKey(carOut
						.getCarInUuid());
				if (!Tools.isEmpty(carInfo))
				{
					ex.setCarInImage1(carInfo.getPic1());
					ex.setCarInimage2(carInfo.getPic2());
					ex.setCarInNo(carInfo.getCarNo());
					ex.setCarInCreatTime(carInfo.getCreateTime());
				}
			}
			
			List<Crossing> list = crossionService
					.queryCrossingByEquimentNo(carOut.getEquipment());
			// 填充路口信息
			if (!Tools.isEmpty(list) && !list.isEmpty())
			{
				ex.setRoadName(list.get(0).getName());
				ex.setRoadUuid(list.get(0).getUuid());
			}
		}
		
		Integer pageNumber = carOutMapper.countAllByPage(page);
		page.setTotalRecords(pageNumber);
	}
	
	@Override
	public BaseMapper<Object, Object, String> getMapper()
	{
		return null;
	}
	
	@Override
	public List<CarParkIn> queryInEquipment(String equipment, Date createTime)
			throws BaseException
	{
		// TODO Auto-generated method stub
		List<CarParkIn> carParkInLs = carInMapper.queryInEquipment(equipment,
				createTime);
		return carParkInLs;
	}
	
	@Override
	public List<CarParkOut> queryOutEquipment(String equipment, Date createTime)
			throws BaseException
	{
		// TODO Auto-generated method stub
		List<CarParkOut> carParkOutLs = carOutMapper.queryOutEquipment(
				equipment, createTime);
		return carParkOutLs;
	}
	
	@Override
	public void updateCarParkInBill(CarParkIn carParkIn) throws BaseException
	{
		// TODO Auto-generated method stub
		try
		{
			if (!Tools.isEmpty(carParkIn.getUuid()))
			{
				carInMapper.updateByPrimaryKeySelective(carParkIn);
			}
			
			/*
			 * if (!Tools.isEmpty(carParkIn.getRecordId())) { CarParkInExample
			 * condition = new CarParkInExample();
			 * condition.or().andRecordIdEqualTo(
			 * carParkIn.getRecordId().trim());
			 * carInMapper.updateByConditionSelective(carParkIn, condition); }
			 */
			
			// carInMapper.updateCarParkInBill(carParkIn);
			UpdateThread updateThread = new UpdateThread(localBizUpdateService,
					CommonContains.TABLE_CAR_OUT, carParkIn.getUuid(),
					carParkIn);
			ThreadPoolUtil.instance().execute(updateThread);
		} catch (Throwable e)
		{
			throw new BaseException(e.getMessage());
		}
	}
	
	@Override
	public void updateCarParkOutBill(CarParkOut carParkOut)
			throws BaseException
	{
		try
		{
			if (!Tools.isEmpty(carParkOut.getUuid()))
			{
				carOutMapper.updateByPrimaryKeySelective(carParkOut);
			}
			
			/*
			 * if (!Tools.isEmpty(carParkOut.getRecordId())) { CarParkOutExample
			 * condition = new CarParkOutExample();
			 * condition.or().andRecordIdEqualTo(
			 * carParkOut.getRecordId().trim());
			 * carOutMapper.updateByConditionSelective(carParkOut, condition); }
			 */
			
			// carOutMapper.updateCarParkOutBill(carParkOut);
			UpdateThread updateThread = new UpdateThread(localBizUpdateService,
					CommonContains.TABLE_CAR_OUT, carParkOut.getUuid(),
					carParkOut);
			ThreadPoolUtil.instance().execute(updateThread);
		} catch (Throwable e)
		{
			throw new BaseException(e.getMessage());
		}
	}
	
	@Override
	public CarParkIn selectCarParkInByPrimaryKey(String recordId)
	{
		return carInMapper.selectByPrimaryKey(recordId);
	}
	
	@Override
	public CarParkOut selectCarParkOutByPrimaryKey(String recordId)
	{
		return carOutMapper.selectByPrimaryKey(recordId);
	}
	
	@Override
	public CarParkIn selectCarParkInByRecordId(String recordId)
	{
		if (Tools.isEmpty(recordId))
		{
			return null;
		}
		
		CarParkInExample condition = new CarParkInExample();
		condition.or().andRecordIdEqualTo(recordId.trim());
		List<CarParkIn> list = carInMapper.selectByCondition(condition);
		return list.isEmpty() ? null : list.get(0);
	}
	
	@Override
	public CarParkOut selectCarParkOutByRecordId(String recordId)
	{
		if (Tools.isEmpty(recordId))
		{
			return null;
		}
		CarParkOutExample condition = new CarParkOutExample();
		condition.or().andRecordIdEqualTo(recordId.trim());
		List<CarParkOut> list = carOutMapper.selectByCondition(condition);
		return list.isEmpty() ? null : list.get(0);
	}
	
	@Override
	public CarInAndOutPhotoVo returnPhotoVo(String uuid) throws BaseException
	{
		// TODO Auto-generated method stub
		CarParkIn carParkIn = carInMapper.selectByPrimaryKey(uuid);
		CarParkOut carParkOut = carOutMapper.selectByPrimaryKey(uuid);
		
		CarInAndOutPhotoVo carInAndOutPhotoVo = new CarInAndOutPhotoVo();
		if (!Tools.isEmpty(carParkIn))
		{
			carInAndOutPhotoVo.setUuid(carParkIn.getUuid());
			if (!Tools.isEmpty(carParkIn.getPic1()))
			{
				String[] picUrl = carParkIn.getPic1().split("_1_");
				carInAndOutPhotoVo.setPic1Url(picUrl[0]);
			}
			if (!Tools.isEmpty(carParkIn.getPic2()))
			{
				String[] picUrl = carParkIn.getPic2().split("_2_");
				carInAndOutPhotoVo.setPic2Url(picUrl[0]);
			}
		}
		if (!Tools.isEmpty(carParkOut))
		{
			carInAndOutPhotoVo.setUuid(carParkOut.getUuid());
			if (!Tools.isEmpty(carParkOut.getPic1()))
			{
				String[] picUrl = carParkOut.getPic1().split("_1_");
				carInAndOutPhotoVo.setPic1Url(picUrl[0]);
			}
			if (!Tools.isEmpty(carParkOut.getPic2()))
			{
				String[] picUrl = carParkOut.getPic2().split("_2_");
				carInAndOutPhotoVo.setPic2Url(picUrl[0]);
			}
		}
		return carInAndOutPhotoVo;
	}
	
	@Override
	public Integer selectCarIn(CarParkIn carParkIn)
	{
		// TODO Auto-generated method stub
		
		return carInMapper.selectCarIn(carParkIn.getCarNo(),
				carParkIn.getOpenTime(), carParkIn.getRecordId());
	}
	
	@Override
	public Integer selectCarOut(CarParkOut carParkOut)
	{
		// TODO Auto-generated method stub
		return carOutMapper.selectCarOut(carParkOut.getCarNo(),
				carParkOut.getOpenTime(), carParkOut.getRecordId());
	}
	
	@Override
	public boolean contrastCarBill(CarParkOut carParkOut)
	{
		// TODO Auto-generated method stub
		LocalPayBill lpb = localPayBillMapper
				.selectCarNo(carParkOut.getCarNo());
		CarParkOut cpo = carOutMapper.selectCarNo(carParkOut.getCarNo());
		CarParkIn cpi = carInMapper.selectCarNo(carParkOut.getCarNo());
		Integer timeOut = 15;
		Date date = new Date(System.currentTimeMillis());
		boolean falg = false;
		
		if (Tools.isEmpty(lpb))
		{
			falg = false;
		} else
		{
			Calendar c = Calendar.getInstance();
			c.setTime(lpb.getPayTime());
			c.add(Calendar.MINUTE, timeOut);
			Date d = c.getTime();
			if (!Tools.isEmpty(cpo))
			{
				// 如果 出场最新记录 - 进场最新记录<0 车辆当前时间没出场
				if (cpo.getCreateTime().getTime()
						- cpi.getCreateTime().getTime() < 0)
				{
					falg = false;
				}
				if (lpb.getPayTime().getTime() - cpi.getCreateTime().getTime() > 0
						&& date.getTime() < d.getTime())
				{
					falg = true;
				} else
				{
					falg = false;
				}
			} else
			{
				if (lpb.getPayTime().getTime() - cpi.getCreateTime().getTime() > 0
						&& date.getTime() < d.getTime())
				{
					falg = true;
				} else
				{
					falg = false;
				}
			}
		}
		
		return falg;
	}
	
	@Override
	public List<CarParkIn> findByCarNoMatch(String carNo)
	{
		// TODO Auto-generated method stub
		String longCarNo = carNo.substring(0, 3);
		String[] ss = longCarNo.split("");
		List<CarParkIn> carParkInLs = carInMapper.findByCarNoMatch(ss);
		return carParkInLs;
	}
	
	@Override
	public void queryLikeCarInByPage(
			CarInAndOutPageInfo<LocalCarInRepertory> page)
	{
		
		// 2016-3-15--lt查询索引------start
		Page<Document> docPage = null;
		if (!Tools.isEmpty(page.getCarNo()))
		{
			// 去掉汉字查询
			page.setCarNo(page.getCarNo().substring(2));
//			docPage = LuceneUtils.pageQueryIndex(page);
			docPage = SearchUtil.pageQueryIndex(LuceneConstants.ROOT_PATH
					+ LocalCarInRepertory.class.getSimpleName(), page);
		}
		
		if (docPage != null && docPage.getList() != null
				&& docPage.getList().size() > 0)
		{
			LocalCarInRepertoryExample ex = new LocalCarInRepertoryExample();
			ex.or().andCarInUuidIn(docPage.getList());
			List<LocalCarInRepertory> list = localCarInRepertoryMapper
					.selectByCondition(ex);
			List<LocalCarInRepertory> carInlist = new ArrayList<LocalCarInRepertory>();
			
			// 按照carInUuid顺序排序
			for (String carInUuid : docPage.getList())
			{
				for (LocalCarInRepertory carIn : list)
				{
					if (carInUuid.equals(carIn.getCarInUuid()))
					{
						CarParkIn carParkIn = carInMapper
								.selectByPrimaryKey(carIn.getCarInUuid());
						if (!Tools.isEmpty(carParkIn))
						{
							carIn.setAttr(carParkIn.getPic1());
						}
						carInlist.add(carIn);
						break;
					}
				}
			}
			
			page.setData(carInlist);
			page.setTotalRecords(docPage.getTotalRecord()
					- docPage.getList().size() + carInlist.size());
		}
		// 2016-3-15--lt查询索引------end
	}
	
	@Override
	public LocalPayBill seachCarOutBill(CarParkOut carParkOut)
	{
		LocalPayBill lpb = localPayBillMapper
				.selectCarNo(carParkOut.getCarNo());
		return lpb;
	}
	
	@Override
	public List<CarParkIn> queryNewCarIn(String stationUuid)
	{
		
		List<CarParkIn> reslutList = carInMapper.queryNewCarIn(stationUuid);
		if (!Tools.isEmpty(reslutList))
		{
			List<CarParkIn> roList = new ArrayList<CarParkIn>();
			for (CarParkIn carIn : reslutList)
			{
				CarParkInEx ex = new CarParkInEx();
				BeanUtil.copyProperties(ex, carIn);
				List<Crossing> list = crossionService
						.queryCrossingByEquimentNo(carIn.getEquipment());
				if (!Tools.isEmpty(list) && !list.isEmpty())
				{
					ex.setRoadName(list.get(0).getName());
					ex.setRoadUuid(list.get(0).getUuid());
				}
				
				// 收费类型
				if (!Tools.isEmpty(carIn.getBrand()))
				{
					LocalChargeBytime rule = billRuleService
							.findByBrandId(carIn.getBrand());
					ex.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3()
							: "未知");
				}
				roList.add(ex);
			}
			return roList;
		}
		return reslutList;
	}
	
	@Override
	public List<CarParkIn> queryStayCarIn(String stationUuid)
	{
		List<CarParkIn> reslutList = carInMapper.queryStayCarIn(stationUuid);
		if (!Tools.isEmpty(reslutList))
		{
			List<CarParkIn> roList = new ArrayList<CarParkIn>();
			for (CarParkIn carIn : reslutList)
			{
				CarParkInEx ex = new CarParkInEx();
				BeanUtil.copyProperties(ex, carIn);
				List<Crossing> list = crossionService
						.queryCrossingByEquimentNo(carIn.getEquipment());
				if (!Tools.isEmpty(list) && !list.isEmpty())
				{
					ex.setRoadName(list.get(0).getName());
					ex.setRoadUuid(list.get(0).getUuid());
				}
				
				// 收费类型
				if (!Tools.isEmpty(carIn.getBrand()))
				{
					LocalChargeBytime rule = billRuleService
							.findByBrandId(carIn.getBrand());
					ex.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3()
							: "未知");
				}
				
				// 进场重复车牌标记信息 2016-8-3
				if (!Tools.isEmpty(carIn.getCarNo())
						&& !carIn.getCarNo().contentEquals("未知"))
				{
					LocalCarInRepertoryExample areayCarInEx = new LocalCarInRepertoryExample();
					areayCarInEx.or().andCarNoEqualTo(carIn.getCarNo().trim());
					List<LocalCarInRepertory> listAdyList = localCarInRepertoryMapper
							.selectByCondition(areayCarInEx);
					if (!listAdyList.isEmpty())
					{
						ex.setReptCarInuuid(listAdyList.get(0).getCarInUuid());
					}
				}
				// end 2016-8-3
				
				roList.add(ex);
			}
			return roList;
		}
		return reslutList;
	}
	
	@Override
	public List<CarParkOut> queryStayCarOut(String stationUuid)
	{
		List<CarParkOut> queryList = carOutMapper.queryStayCarOut(stationUuid);
		if (!Tools.isEmpty(queryList))
		{
			List<CarParkOut> carOutList = new ArrayList<CarParkOut>();
			for (CarParkOut outInfo : queryList)
			{
				CarParkOutEx ex = new CarParkOutEx();
				BeanUtil.copyProperties(ex, outInfo);
				List<Crossing> list = crossionService
						.queryCrossingByEquimentNo(outInfo.getEquipment());
				// 填充路口信息
				if (!Tools.isEmpty(list) && !list.isEmpty())
				{
					ex.setRoadName(list.get(0).getName());
					ex.setRoadUuid(list.get(0).getUuid());
				}
				// 填充进场数据
				if (!Tools.isEmpty(outInfo.getCarInUuid()))
				{
					CarParkIn carInfo = carInMapper.selectByPrimaryKey(outInfo
							.getCarInUuid());
					if (!Tools.isEmpty(carInfo))
					{
						ex.setCarInImage1(carInfo.getPic1());
						ex.setCarInimage2(carInfo.getPic2());
						ex.setCarInNo(carInfo.getCarNo());
						ex.setCarInCreatTime(carInfo.getCreateTime());
					}
				}
				
				// 收费类型
				if (!Tools.isEmpty(outInfo.getBrand()))
				{
					LocalChargeBytime rule = billRuleService
							.findByBrandId(outInfo.getBrand());
					ex.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3()
							: "未知");
				}
				
				carOutList.add(ex);
			}
			return carOutList;
		}
		return queryList;
	}
	
	@Override
	public CarParkIn queryCarInByUuid(String uuid)
	{
		CarParkIn cc = carInMapper.selectByPrimaryKey(uuid);
		if (!Tools.isEmpty(cc))
		{
			if (!Tools.isEmpty(cc.getEquipment()))
			{
				LocalEquipmentExample condtion = new LocalEquipmentExample();
				condtion.or().andCameraNoEqualTo(cc.getEquipment());
				List<LocalEquipment> list = localEquipmentMapper
						.selectByCondition(condtion);
				if (!Tools.isEmpty(list) && list.size() > 0)
				{
					cc.setRoadNmae(!Tools.isEmpty(list.get(0)
							.getIntersectionName()) ? list.get(0)
							.getIntersectionName() : "正门进");
				}
				
			}
			return cc;
		}
		return null;
	}
	
	@Override
	public CarParkOutEx queryCarOutByUuid(String uuid)
	{
		CarParkOut carOut = carOutMapper.selectByPrimaryKey(uuid);
		if (!Tools.isEmpty(carOut))
		{
			CarParkOutEx ex = new CarParkOutEx();
			BeanUtil.copyProperties(ex, carOut);
			
			if (!Tools.isEmpty(carOut.getCarInUuid()))
			{
				ex.setCarInInfo(carInMapper.selectByPrimaryKey(carOut
						.getCarInUuid()));
			}
			
			return ex;
		}
		return null;
	}
	
	@Override
	public Integer asyncPhotoForInOrOut(CarBillVo ftpInfo) throws BaseException
	{
		try
		{
			if (log.isDebugEnabled())
			{
				log.debug("处理图片更新,子线程ID"
						+ Thread.currentThread().getId()
						+ ",纪录ID"
						+ ftpInfo.getRecordId()
						+ ",纪录锁定状态:"
						+ RecordLockManager.instance().isLocked(
								ftpInfo.getRecordId()));
			}
			
			// 纪录日志
			if (Tools.isEmpty(ftpInfo.getEquipment()))
			{
				// TODO lyf 纪录相机无法获取
			}
			
			String nginxUrl = reportConfigManager.instance().getCfgValueByKey(
					"nginxUrl");
			String nginxSplit = reportConfigManager.instance()
					.getCfgValueByKey("nginxSplit");
			
			if (nginxUrl == null || "".equals(nginxUrl))
			{
				nginxUrl = "http://localhost:8088";
			}
			if (nginxSplit == null || "".equals(nginxSplit))
			{
				nginxSplit = ":21";
			}
			if (!Tools.isEmpty(ftpInfo.getPic1()))
			{
				String fp1 = nginxUrl
						+ ftpInfo.getPic1().substring(
								ftpInfo.getPic1().lastIndexOf(nginxSplit) + 3,
								ftpInfo.getPic1().length());
				ftpInfo.setPic1(!Tools.isEmpty(fp1) ? fp1 : ftpInfo.getPic1());
			}
			if (!Tools.isEmpty(ftpInfo.getPic2()))
			{
				String fp2 = nginxUrl
						+ ftpInfo.getPic2().substring(
								ftpInfo.getPic2().lastIndexOf(nginxSplit) + 3,
								ftpInfo.getPic2().length());
				ftpInfo.setPic2(!Tools.isEmpty(fp2) ? fp2 : ftpInfo.getPic2());
			}
			
			// 进场
			if (ftpInfo.getUserType().equals("1"))
			{
				long carInwaitTime = 0;
				// 判断锁
				while (RecordLockManager.instance().isLocked(
						ftpInfo.getRecordId()))
				{
					carInwaitTime += 1000;
					Thread.sleep(1000);
					if (log.isDebugEnabled())
					{
						log.debug("->进场纪录等待锁,线程ID"
								+ Thread.currentThread().getId() + "，纪录ID"
								+ ftpInfo.getRecordId() + "线程ID"
								+ Thread.currentThread().getId());
					}
					if (carInwaitTime >= 1000 * 60) // 一分钟之后自动放弃
					{
						if (log.isDebugEnabled())
						{
							log.debug("->进场纪录放弃锁,线程ID"
									+ Thread.currentThread().getId() + "，纪录ID"
									+ ftpInfo.getRecordId() + "线程ID"
									+ Thread.currentThread().getId());
						}
						break;
					}
				}
				
				if (log.isDebugEnabled())
				{
					log.debug("->进场纪录执行图片更新,线程ID"
							+ Thread.currentThread().getId() + "，纪录ID"
							+ ftpInfo.getRecordId() + "线程ID"
							+ Thread.currentThread().getId());
				}
				
				CarParkIn carInInfo = selectCarParkInByRecordId(ftpInfo
						.getRecordId());
				if (!Tools.isEmpty(carInInfo))
				{
					carInInfo.setPic1(ftpInfo.getPic1());
					carInInfo.setPic2(ftpInfo.getPic2());
					
					if (!Tools.isEmpty(carInInfo))
					{
						carInMapper.updateByPrimaryKeySelective(carInInfo);
						ftpInfo.setPushImage(true);
					}
				}
				
				// 更新副本表图片 2016-1-30
				if (Tools.isEmpty(carInInfo))
				{
					CarParkInCopyExample carInCpEx = new CarParkInCopyExample();
					carInCpEx.or().andRecordIdEqualTo(ftpInfo.getRecordId());
					List<CarParkInCopy> list = carParkInCopyMapper
							.selectByCondition(carInCpEx);
					
					if (!Tools.isEmpty(list) && !list.isEmpty())
					{
						CarParkInCopy carIncopy = new CarParkInCopy();
						carIncopy.setPic1(ftpInfo.getPic1());
						carIncopy.setPic2(ftpInfo.getPic2());
						carIncopy.setUuid(list.get(0).getUuid());
						carParkInCopyMapper
								.updateByPrimaryKeySelective(carIncopy);
						ftpInfo.setPushImage(true);
						// 克隆到进场对象
						carInInfo = new CarParkIn();
						BeanUtil.copyProperties(carInInfo, list.get(0));
					}
				}// end if
				
				// 上报
				if (!Tools.isEmpty(carInInfo)
						&& reportConfigManager.instance().isOpen())
				{
					// 上报系统，转换
					ReportCarInfoVo reportCarInfoVo = this
							.ReportCarInfoVoIn(carInInfo);
					
					UploadReportCarInfoRunble report = new UploadReportCarInfoRunble(
							reportCarInfoVo, logServier);
					ThreadPoolUtil.instance().execute(report);
				}// end
			}
			
			// 出场
			if (ftpInfo.getUserType().equals("2"))
			{
				long carOutwaitTime = 0;
				// 判断锁
				while (RecordLockManager.instance().isLocked(
						ftpInfo.getRecordId()))
				{
					carOutwaitTime += 1000;
					Thread.sleep(1000);
					if (log.isDebugEnabled())
					{
						log.debug("--->等待锁（出）线程ID："
								+ Thread.currentThread().getId() + "，纪录ID"
								+ ftpInfo.getRecordId() + "，线程Id"
								+ Thread.currentThread().getId());
					}
					if (carOutwaitTime >= 1000 * 60) // 一分钟后放弃
					{
						if (log.isDebugEnabled())
						{
							log.debug("--->放弃锁(出),线程ID："
									+ Thread.currentThread().getId() + "，纪录ID"
									+ ftpInfo.getRecordId() + "，线程ID"
									+ Thread.currentThread().getId());
						}
						break;
					}
				}
				
				if (log.isDebugEnabled())
				{
					log.debug("--->执行更新图片(出)，线程ID："
							+ Thread.currentThread().getId() + "，纪录ID"
							+ ftpInfo.getRecordId() + "，线程ID"
							+ Thread.currentThread().getId());
				}
				
				log.debug("更新图片获得锁,线程ID:" + Thread.currentThread().getId()
						+ ",纪录ID" + ftpInfo.getRecordId());
				RecordLockManager.instance().lock(ftpInfo.getRecordId());
				
				CarParkOut carOut = selectCarParkOutByRecordId(ftpInfo
						.getRecordId());
				
				if (!Tools.isEmpty(carOut))
				{
					carOut.setPic1(ftpInfo.getPic1());
					carOut.setPic2(ftpInfo.getPic2());
					
					if (!Tools.isEmpty(carOut))
					{
						carOutMapper.updateByPrimaryKey(carOut);
					}
					ftpInfo.setPushImage(true);
				}
				
				if (Tools.isEmpty(carOut))
				{
					// 更新副本表
					CarParkOutCopyExample carOutCopyEx = new CarParkOutCopyExample();
					carOutCopyEx.or().andRecordIdEqualTo(ftpInfo.getRecordId());
					List<CarParkOutCopy> list = carOutCopyMapper
							.selectByCondition(carOutCopyEx);
					if (!Tools.isEmpty(list) && !list.isEmpty())
					{
						CarParkOutCopy carOutCopy = new CarParkOutCopy();
						carOutCopy.setUuid(list.get(0).getUuid());
						carOutCopy.setPic1(ftpInfo.getPic1());
						carOutCopy.setPic2(ftpInfo.getPic2());
						carOutCopyMapper
								.updateByPrimaryKeySelective(carOutCopy);
						ftpInfo.setPushImage(true);
						
						carOut = new CarParkOut();
						// 克隆到进场对象
						BeanUtil.copyProperties(carOut, list.get(0));
					}
				}
				
				// 上报
				if (!Tools.isEmpty(carOut)
						&& reportConfigManager.instance().isOpen())
				{
					// 上报系统，转换
					ReportCarInfoVo pr = this.ReportCarInfoVoOut(carOut);
					
					UploadReportCarInfoRunble upload = new UploadReportCarInfoRunble(
							pr, logService);
					ThreadPoolUtil.instance().execute(upload);
				}// end
				
				log.debug("更新图片释放锁,线程ID:" + Thread.currentThread().getId()
						+ ",纪录ID" + ftpInfo.getRecordId());
				RecordLockManager.instance().removeLock(ftpInfo.getRecordId());
				
			}
			
		} catch (Throwable t)
		{
			log.error("update-image", t);
		}
		return null;
	}
	
	@Override
	public Map<String, Object> getIdentityTypeByCarNo(String carNo)
	{
		// 如： 1. 临时车 2.会员 3.平台用户 4.白名单 5.黑名单 6.黄名单 7.免费卡
		Map<String, Object> map = new HashMap<String, Object>();
		String type = MessageContains.TEMP_CAR_TYPE;
		
		LocalBlackList lbl = localBlackListService.queryBlackListByCarNo(carNo
				.trim());
		
		if (!Tools.isEmpty(lbl))
		{
			type = BlackAndWhiteCfgManager.instance().getValueByKey(
					lbl.getType().trim());
			map.put("expireTime", lbl.getEndTime());
			map.put("carNoType", type);
			return map;
		}
		
		// 查询车辆是否为免费卡
		FreeCar freecar = freeCarService.queryFreeCarNo(carNo.trim());
		if (!Tools.isEmpty(freecar))
		{
			Date now = new Date();
			// 判断当前时间是否有效 //判断免费卡状态是否为 正常 (1:正常 2:停用)
			if (now.before(freecar.getTimeInterval())
					&& freecar.getStatus() == 1)
			{
				type = BlackAndWhiteCfgManager.instance().getValueByKey("7");
				map.put("expireTime", freecar.getTimeInterval());
				map.put("carNoType", type);
				return map;
			}
		}
		
		// 通过 车场ID、车牌号、当前时间，（时间是否在类型有效中）。查找此车，是否有会员。且会员是否有效
		List<LocalMember> parkwellMemberCards = parkwellMemberService
				.findCarNoIsMemberInPark(carNo.trim(),
						new Date(System.currentTimeMillis()));
		if (ConfigManager.instance().isCloudPay())
		{
			// 查询平台会员
			IntegrationExample inEx = new IntegrationExample();
			inEx.or().andCarNoEqualTo(carNo.trim());
			List<Integration> intList = interationMapper
					.selectByCondition(inEx);
			if (!Tools.isEmpty(intList) && !intList.isEmpty())
			{
				// 5="平台用户"
				type = BlackAndWhiteCfgManager.instance().getValueByKey("5");
			}
		}
		// 设置是否是会员
		if (!Tools.isEmpty(parkwellMemberCards)
				&& !parkwellMemberCards.isEmpty())
		{
			type = "会员";
			map.put("carNoType", type);
			map.put("expireTime", parkwellMemberCards.get(0).getEndTime());
			map.put("startTime", parkwellMemberCards.get(0).getStartTime());
			return map;
		}
		map.put("carNoType", type);
		return map;
	}
	
	@Override
	public boolean parkIn(CarParkIn carParkIn) throws BaseException
	{
		// TODO Auto-generated method stub
		if (Tools.isEmpty(carParkIn.getCarNo()))
		{
			carParkIn.setCarNo("无效车牌");
		}
		
		carParkIn.setUuid(UUIDGenerateUtil.generate());
		carParkIn.setCreateTime(new Date());
		carParkIn.setStatus(1);
		carInMapper.insertSelective(carParkIn);
		
		if (carParkIn.getStatus() == 1 && !Tools.isEmpty(carParkIn.getUuid())
				&& !carParkIn.getCarNo().equals("")
				&& !carParkIn.getCarNo().equalsIgnoreCase("无效车牌"))
		{
			CarParkInExample inEx = new CarParkInExample();
			inEx.or().andUuidNotEqualTo(carParkIn.getUuid())
					.andStatusEqualTo(1).andCarNoEqualTo(carParkIn.getCarNo());
			carInMapper.deleteByCondition(inEx);
		}
		
		// 计费规则放入副本表
		List<LocalChargeBytimeCopy> lis = localChargeByTimeCopyService
				.addRuleCopy(carParkIn);
		// 计费规则副本放入云端
		localChargeByTimeCopyService.setRuleUploadCopy(lis);
		
		// Status=0 表示已经出场 1 表示已经入场 2表示待入场 ,只有车辆确认进场才同步到云平台
		if (CloudConfigManager.instance().isOpen()
				&& carParkIn.getStatus() == 1)
		{
			UploadCarInInfoRunble upload = new UploadCarInInfoRunble(carParkIn,
					logService);
			ThreadPoolUtil.instance().execute(upload);
		}
		return true;
	}
	
	@Override
	public Integer deleteCarInInfo(List<String> uuids) throws BaseException
	{
		try
		{
			CarParkInExample condition = new CarParkInExample();
			condition.or().andUuidIn(uuids);
			carInMapper.deleteByCondition(condition);
		} catch (Throwable t)
		{
			log.error(t.getMessage(), t);
			throw new BaseException(t.getMessage());
		}
		return 1;
	}
	
	@Override
	public Integer deleteCarOutInfo(List<String> uuids) throws BaseException
	{
		try
		{
			CarParkOutExample condition = new CarParkOutExample();
			condition.or().andUuidIn(uuids);
			carOutMapper.deleteByCondition(condition);
		} catch (Throwable t)
		{
			log.error(t.getMessage(), t);
			throw new BaseException(t.getMessage());
		}
		return 1;
	}
	
	public com.local.model.CarParkIn returnCarParkIn(
			com.other.controller.entity.CarParkIn carParkIn)
	{
		com.local.model.CarParkIn cc = new com.local.model.CarParkIn();
		cc.setUuid(UUIDGenerateUtil.generate());
		cc.setCarNo(carParkIn.getCarNo());
		cc.setCreateTime(new Date(System.currentTimeMillis()));
		cc.setPic1(!Tools.isEmpty(carParkIn.getPic_1()) ? carParkIn.getPic_1()
				: null);
		cc.setPic2(!Tools.isEmpty(carParkIn.getPic_2()) ? carParkIn.getPic_2()
				: null);
		String exchanuui = CloudConfigManager.instance().getCfgValueByKey(
				"exchange_id");
		cc.setExchangeUuid(exchanuui);
		cc.setEquipment(!Tools.isEmpty(carParkIn.getDeviceNo()) ? carParkIn
				.getDeviceNo() : null);
		cc.setOpenTime(!Tools.isEmpty(carParkIn.getCarInTime()) ? carParkIn
				.getCarInTime() : null);
		return cc;
	}
	
	@Override
	public ReportCarInfoVo ReportCarInfoVoIn(CarParkIn carParkIn)
			throws BaseException
	{
		ReportCarInfoVo reportCarInfoVo = new ReportCarInfoVo();
		// TODO Auto-generated method stub
		if (!Tools.isEmpty(carParkIn))
		{
			reportCarInfoVo
					.setCarNo(!Tools.isEmpty(carParkIn.getCarNo()) ? carParkIn
							.getCarNo() : "无");
			reportCarInfoVo.setPassType(0);
			reportCarInfoVo.setUrlType(1);
			reportCarInfoVo
					.setPassID(!Tools.isEmpty(carParkIn.getEquipment()) ? carParkIn
							.getEquipment() : null);
			SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			reportCarInfoVo.setOptionTime(!Tools.isEmpty(carParkIn
					.getOpenTime()) ? carParkIn.getOpenTime() : dd
					.format(carParkIn.getCreateTime()));
			reportCarInfoVo
					.setImagePath(!Tools.isEmpty(carParkIn.getPic1()) ? carParkIn
							.getPic1() : null);
		}
		return reportCarInfoVo;
	}
	
	@Override
	public ReportCarInfoVo ReportCarInfoVoOut(CarParkOut carParkOut)
			throws BaseException
	{
		ReportCarInfoVo reportCarInfoVo = new ReportCarInfoVo();
		// TODO Auto-generated method stub
		if (!Tools.isEmpty(carParkOut))
		{
			reportCarInfoVo
					.setCarNo(!Tools.isEmpty(carParkOut.getCarNo()) ? carParkOut
							.getCarNo() : "无");
			reportCarInfoVo.setPassType(1);
			reportCarInfoVo.setUrlType(1);
			reportCarInfoVo
					.setPassID(!Tools.isEmpty(carParkOut.getEquipment()) ? carParkOut
							.getEquipment() : null);
			SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			reportCarInfoVo.setOptionTime(!Tools.isEmpty(carParkOut
					.getOpenTime()) ? carParkOut.getOpenTime() : dd
					.format(carParkOut.getCreateTime()));
			reportCarInfoVo
					.setImagePath(!Tools.isEmpty(carParkOut.getPic1()) ? carParkOut
							.getPic1() : null);
		}
		return reportCarInfoVo;
	}
	
	@Override
	public Integer deleteCarInCopyInfo(List<String> uuids) throws BaseException
	{
		// TODO Auto-generated method stub
		try
		{
			CarParkInCopyExample condition = new CarParkInCopyExample();
			condition.or().andUuidIn(uuids);
			carParkInCopyMapper.deleteByCondition(condition);
		} catch (Throwable t)
		{
			log.error(t.getMessage(), t);
			throw new BaseException(t.getMessage());
		}
		return 1;
	}
	
	@Override
	public Integer deleteCarOutCopyInfo(List<String> uuids)
			throws BaseException
	{
		// TODO Auto-generated method stub
		try
		{
			if (Tools.isEmpty(uuids))
			{
				carOutCopyMapper.deleteAll();
			} else
			{
				CarParkOutCopyExample condition = new CarParkOutCopyExample();
				condition.or().andUuidIn(uuids);
				carOutCopyMapper.deleteByCondition(condition);
			}
		} catch (Throwable t)
		{
			log.error(t.getMessage(), t);
			throw new BaseException(t.getMessage());
		}
		return 1;
	}
	
	@Override
	public void queryCarInCopyByPage(CarInAndOutPageInfo<CarParkInCopy> page)
	{
		// TODO Auto-generated method stub
		List<CarParkInCopy> dataList = carParkInCopyMapper.queryByPage(page);
		// page.setData(dataList);
		
		List<CarParkInCopy> roList = new ArrayList<CarParkInCopy>();
		page.setData(roList);
		for (CarParkInCopy carIn : dataList)
		{
			CarParkInCopyEx ex = new CarParkInCopyEx();
			BeanUtil.copyProperties(ex, carIn);
			List<Crossing> list = crossionService
					.queryCrossingByEquimentNo(carIn.getEquipment());
			if (!Tools.isEmpty(list) && !list.isEmpty())
			{
				ex.setRoadName(list.get(0).getName());
				ex.setRoadUuid(list.get(0).getUuid());
			}
			roList.add(ex);
		}
		Integer pageNumber = carParkInCopyMapper.countAllByPage(page);
		page.setTotalRecords(pageNumber);
	}
	
	@Override
	public void queryCarOutCopyByPage(CarInAndOutPageInfo<CarParkOutCopy> page)
	{
		// TODO need test
		Page<Document> docPage = null;
		if (!Tools.isEmpty(page.getCarNo()))
		{
			// docPage = Lucene.singleton(CarParkOutCopy.class).pageQueryIndex(
			// LuceneConstants.CAR_NO, page, LuceneConstants.CAR_OUT_UUID);
			docPage = SearchUtil.pageQueryIndex(LuceneConstants.ROOT_PATH
					+ CarParkOutCopy.class.getSimpleName(), page);
		}
		
		List<CarParkOutCopy> dataList = null;
		
		if (docPage != null && docPage.getList() != null
				&& docPage.getList().size() > 0)
		{
			CarParkOutCopyExample example = new CarParkOutCopyExample();
			example.createCriteria().andCarInUuidIn(docPage.getList());
			// TODO Auto-generated method stub
			dataList = carOutCopyMapper.selectByCondition(example);
		} else
		{
			dataList = carOutCopyMapper.queryByPage(page);
		}
		
		// page.setData(dataList);
		List<CarParkOutCopy> listCarOutEx = new ArrayList<CarParkOutCopy>();
		page.setData(listCarOutEx);
		
		for (CarParkOutCopy carOut : dataList) // 获取进场信息
		{
			CarParkOutCopyEx ex = new CarParkOutCopyEx();
			BeanUtil.copyProperties(ex, carOut);
			listCarOutEx.add(ex);
			
			// 车辆类型，大车小车
			if (!Tools.isEmpty(carOut.getType()))
			{
				
				LocalCarType typeInfo = catTypeMapper.selectByPrimaryKey(carOut
						.getType());
				if (!Tools.isEmpty(typeInfo))
				{
					ex.setCarTypeName(typeInfo.getCartypeName());
				}
			}
			
			// 收费类型
			if (!Tools.isEmpty(carOut.getBrand()))
			{
				LocalChargeBytime rule = billRuleService.findByBrandId(carOut
						.getBrand());
				ex.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3() : "未知");
			}
			
			if (!Tools.isEmpty(carOut.getCarInUuid()))
			{
				CarParkInCopy carParkInCopy = carParkInCopyMapper
						.selectByPrimaryKey(carOut.getCarInUuid());
				if (!Tools.isEmpty(carParkInCopy))
				{
					ex.setStayTime(carOut.getCreateTime().getTime()
							- carParkInCopy.getCreateTime().getTime());
				}
				List<LocalPayBill> localPayBills = localPayBillMapper
						.queryAllBill(carOut.getCarInUuid());
				Double totalPrice = 0.0;
				for (LocalPayBill localPayBill : localPayBills)
				{
					totalPrice += localPayBill.getPrice();
				}
				ex.setTotalMoney(!Tools.isEmpty(totalPrice) ? totalPrice : 0d);
				CarParkInCopy carInfo = carParkInCopyMapper
						.selectByPrimaryKey(carOut.getCarInUuid());
				if (!Tools.isEmpty(carInfo))
				{
					ex.setCarInImage1(carInfo.getPic1());
					ex.setCarInimage2(carInfo.getPic2());
					ex.setCarInNo(carInfo.getCarNo());
					ex.setCarInCreatTime(carInfo.getCreateTime());
				}
			}
			List<Crossing> list = crossionService
					.queryCrossingByEquimentNo(carOut.getEquipment());
			// 填充路口信息
			if (!Tools.isEmpty(list) && !list.isEmpty())
			{
				ex.setRoadName(list.get(0).getName());
				ex.setRoadUuid(list.get(0).getUuid());
			}
		}
		
		if (docPage != null && docPage.getList() != null
				&& docPage.getList().size() > 0)
		{
			// 重置一次总数
			page.setTotalRecords(docPage.getTotalRecord() - dataList.size()
					+ listCarOutEx.size());
		} else
		{
			Integer pageNumber = carOutCopyMapper.countAllByPage(page);
			page.setTotalRecords(pageNumber);
		}
	}
	
	@Override
	public CarParkIn findCarInByCarNo(String carNo)
	{
		CarParkInExample ex = new CarParkInExample();
		ex.or().andStatusEqualTo(1).andCarNoEqualTo(carNo.trim());
		List<CarParkIn> list = carInMapper.selectByCondition(ex);
		return !Tools.isEmpty(list) ? !list.isEmpty() ? list.get(0) : null
				: null;
	}
	
	@Override
	public Integer deleteCarParkIn(Date carInDays)
	{
		CarParkInExample condtion = new CarParkInExample();
		condtion.or().andCreateTimeLessThan(carInDays);
		Integer result = carInMapper.deleteByCondition(condtion);
		// TODO Auto-generated method stub
		if (!Tools.isEmpty(result))
		{
			return result;
		} else
		{
			return null;
		}
	}
	
	@Override
	public Integer deleteCarParkOut(Date carOutDays)
	{
		// TODO Auto-generated method stub
		CarParkOutExample condtion = new CarParkOutExample();
		condtion.or().andCreateTimeLessThan(carOutDays);
		Integer result = carOutMapper.deleteByCondition(condtion);
		if (!Tools.isEmpty(result))
		{
			return result;
		} else
		{
			return null;
		}
	}
	
	@Override
	public Integer deleteCarParkInCopy(Date carInHistoryDays)
	{
		// TODO Auto-generated method stub
		CarParkInCopyExample condtion = new CarParkInCopyExample();
		condtion.or().andCreateTimeLessThan(carInHistoryDays);
		Integer result = carParkInCopyMapper.deleteByCondition(condtion);
		if (!Tools.isEmpty(result))
		{
			return result;
		} else
		{
			return null;
		}
	}
	
	@Override
	public Integer deleteCarParkOutCopy(Date carOutHistoryDays)
	{
		// TODO Auto-generated method stub
		CarParkOutCopyExample condtion = new CarParkOutCopyExample();
		condtion.or().andCreateTimeLessThan(carOutHistoryDays);
		Integer result = carOutCopyMapper.deleteByCondition(condtion);
		if (!Tools.isEmpty(result))
		{
			return result;
		} else
		{
			return null;
		}
	}
	
	@Override
	public void batchCreateCarParkInIndex()
	{
		// 以前索引的表
		// List<CarParkIn> carInList = carInMapper.queryCarParkIn();
		
		//TODO neet test
		List<LocalCarInRepertory> carInList = localCarInRepertoryMapper
				.queryCarInRepertory();
		
		IndexWriter writer = IndexUtil.getIndexWriter(LuceneConstants.ROOT_PATH + 
				LocalCarInRepertory.class.getSimpleName(), true);
		List<Map<FieldEnum, Object>> list = new ArrayList<Map<FieldEnum,Object>>();
		for(LocalCarInRepertory  carInRepertory: carInList)
        {
        	if(!Tools.isEmpty(carInRepertory.getCarNo()) && !Tools.isEmpty(carInRepertory.getCarInUuid())){
				Map<FieldEnum, Object> map = new HashMap<FieldEnum, Object>();
				map.put(FieldEnum.CONTENTS, carInRepertory.getCarNo());
				map.put(FieldEnum.MODIFY_TIME, carInRepertory.getCarInTime());
				map.put(FieldEnum.STRING_FIELD, carInRepertory.getCarInUuid());
				list.add(map);
			}
        }
		IndexUtil.indexDoc(writer, list);
		IndexUtil.closeWriter();
		// 新增索引
//		LuceneUtils.batchCreateIndex(carInList);
	}
	
	@Override
	public void localCarParkInData(CarParkInOverVo carInVo)
			throws BaseException
	{
		try
		{
			// 删除滚动计费表信息,如果已经开闸则删除非当天滚动计费信息
			if (carInVo.isOpen() && !Tools.isEmpty(carInVo.getCarparkIn())
					&& !carInVo.getCarparkIn().getCarNo().equals("无效车牌"))
			{
				ParkwellPayBillVo billVo = new ParkwellPayBillVo();
				billVo.setCarNo(carInVo.getCarparkIn().getCarNo());
				payBilllService.delRepaetBillNotInDay(billVo);
			}
			
			// 判断是否重复入场&重复入场提示开关
			if (!carInVo.isReptCarNoWhenCarInCrt() && carInVo.isReptCaoNo()) // 开关打开,并且已重复
			{
				carInVo.setOpen(false);
				carInVo.getCarparkIn().setStatus(2);
			} else
			{
				if (!carInVo.getCarparkIn().getCarNo().equals("无效车牌"))
				{
					// 删除重复
					// carInVo.getCarparkIn().setStatus(1);
					CarParkInExample inEx = new CarParkInExample();
					inEx.or()
							.andUuidNotEqualTo(carInVo.getCarparkIn().getUuid())
							.andCarNoEqualTo(carInVo.getCarparkIn().getCarNo());
					carInMapper.deleteByCondition(inEx);
				}
			}
			
			// 填充岗亭信息 2016-8-9
			if (!Tools.isEmpty(carInVo.getRoadUuid()))
			{
				LocalStation station = crossinService
						.findStationByCrosId(carInVo.getRoadUuid());
				if (!Tools.isEmpty(station))
				{
					carInVo.getCarparkIn().setStationUuid(
							station.getStationUuid());
				}
			}
			// end 2016-8-9
			
			// 插入进场信息
			carInMapper.insertSelective(carInVo.getCarparkIn());
			
			// 默认开闸的添加入场仓库表，避免太多垃圾数据.（进场时插入出场结果）
			if (!Tools.isEmpty(carInVo.getCarparkIn())
					&& carInVo.getCarparkIn().getStatus().intValue() == 1)
			{
				this.inserCarInRepertory(carInVo);
			}
			
		} catch (Throwable e)
		{
			throw new BaseException(e.getMessage());
		}
	}
	
	@Override
	public void pushCarParkInInfo(CarParkInOverVo carInVo) throws BaseException
	{
		try
		{
			if (!Tools.isEmpty(carInVo)
					&& !Tools.isEmpty(carInVo.getCarparkIn()))
			{
				// Status=0 表示已经出场 1 表示已经入场 2表示待入场 ,只有车辆确认进场才同步到云平台
				if (CloudConfigManager.instance().isOpen()
						&& carInVo.getCarparkIn().getStatus() == 1)
				{
					this.uploadCarInInfo(carInVo.getCarparkIn());
				}
			}
			
		} catch (Throwable t)
		{
			log.error("", t);
		}
	}
	
	/**
	 * 
	 * 方法描述：计费规则副本放入云端
	 * 
	 * @Title: setRuleCopyRunble @param @param localChargeBytimeCopy @return
	 *         void @user Administrator 2016年3月25日 @throws
	 */
	public void setRuleCopy(LocalChargeBytimeCopy localChargeBytimeCopy)
	{
		// 发送请求
		CloseableHttpClient httpClient = HttpManagerUtil.getInstance()
				.getHttpClient(null);
		try
		{
			
			if (Tools.isEmpty(localChargeBytimeCopy))
			{
				return;
			}
			// 获取请求路径
			String uri = CloudConfigManager.instance().getHost()
					+ CloudConfigManager.instance().getCfgValueByKey(
							"sync_rule_copy");
			String exchanuui = CloudConfigManager.instance().getCfgValueByKey(
					"exchange_id");
			localChargeBytimeCopy.setParkOrgCode(exchanuui);
			HttpPost post = new HttpPost(uri);
			post.setHeader("Content-Type", "application/json;charset=UTF-8");
			post.setConfig(HttpClientUtil.getTimeOutCfg(0));
			String sendData = JsonUtil.getJsonString(localChargeBytimeCopy);
			StringEntity s = new StringEntity(sendData, "UTF-8");
			post.setEntity(s);
			
			log.debug("上传计费规则副本[信息]:" + sendData);
			
			CloseableHttpResponse resp = httpClient.execute(post);
			String result = EntityUtils.toString(resp.getEntity(), "UTF-8");
			
			log.debug("上传计费规则副本[返回]:" + result);
			
			ResultVo resultVo = (ResultVo) JsonUtil.getObjectByJson(result,
					ResultVo.class);
			
			if (resultVo.getResult().equals("success"))
			{
				System.out.println("上传计费规则副本[信息]成功..");
			} else
			{
				System.out.println("上传计费规则副本[信息]失败.");
				System.out.println(resultVo.getErrorMsg());
				
				addErrorLogRuleCopy(
						localChargeBytimeCopy.getChargeBytimeUuid(),
						"上传计费规则副本[信息]失败.");
			}
			
		} catch (Throwable t)
		{
			log.error("", t);
			addErrorLogRuleCopy(localChargeBytimeCopy.getChargeBytimeUuid(),
					"上传计费规则副本[信息]失败.");
			try
			{
				if (httpClient != null)
				{
					httpClient.close();
				}
			} catch (IOException localIOException1)
			{
			}
		} finally
		{
			try
			{
				if (null != httpClient)
				{
					httpClient.close();
				}
			} catch (IOException e)
			{
				
			}
		}
	}
	
	/**
	 * 
	 * 方法描述：上传计费规则副本 异常
	 * 
	 * @Title: addErrorLogRuleCopy @param @param businessUuid @param @param
	 *         deScript @return void @user Administrator 2016年3月29日 @throws
	 */
	public void addErrorLogRuleCopy(String businessUuid, String deScript)
	{
		Log logInfo = new Log();
		logInfo.setCreaterAt(new Date());
		logInfo.setSummary("上传计费副本异常.");
		logInfo.setDescript(deScript);
		logInfo.setLevel(LogInfoConstan.LEVEL_ALERT);
		logInfo.setSrc(LogInfoConstan.SRC_SYSTEM);
		logInfo.setStatus(LogInfoConstan.STATUS_UNTREATED);
		logInfo.setCls("com.cloud.threads.SetRuleUploadCopyRunble");
		logInfo.setModule(LogInfoConstan.RULE_COPY_UPLOAD);
		logInfo.setBusinessUuid(businessUuid);
		logServier.addLogInfo(logInfo);
	}
	
	/**
	 * 
	 * 方法描述：当车辆入场是把数据同步到云平台
	 * 
	 * @Title: uploadCarInInfo @param @param carparkin @return void @user
	 *         Administrator 2016年3月25日 @throws
	 */
	public void uploadCarInInfo(CarParkIn carparkin)
	{
		// 发送请求
		CloseableHttpClient httpClient = HttpManagerUtil.getInstance()
				.getHttpClient(null);
		try
		{
			
			if (Tools.isEmpty(carparkin))
			{
				return;
			}
			// 获取请求路径
			String uri = CloudConfigManager.instance().getHost()
					+ CloudConfigManager.instance().getCfgValueByKey(
							"sync_car_in");
			
			HttpPost post = new HttpPost(uri);
			post.setHeader("Content-Type", "application/json;charset=UTF-8");
			post.setConfig(HttpClientUtil.getTimeOutCfg(0));
			String sendData = JsonUtil.getJsonString(carparkin);
			StringEntity s = new StringEntity(sendData, "UTF-8");
			post.setEntity(s);
			
			log.debug("上传进场纪录[信息]:" + sendData);
			
			CloseableHttpResponse resp = httpClient.execute(post);
			String result = EntityUtils.toString(resp.getEntity(), "UTF-8");
			
			log.debug("上传进场纪录[返回]:" + sendData);
			
			ResultVo resultVo = (ResultVo) JsonUtil.getObjectByJson(result,
					ResultVo.class);
			
			if (resultVo.getResult().equals("success"))
			{
				System.out.println(carparkin.getCarNo() + ",上传进场纪录成功..");
			} else
			{
				System.out.println(carparkin.getCarNo() + ",上传进场纪录失败.");
				System.out.println(resultVo.getErrorMsg());
				
				addErrorLogUploadCarInInfo(carparkin.getUuid(), ",上传进场纪录失败.");
			}
			
		} catch (Throwable t)
		{
			log.error("", t);
			addErrorLogUploadCarInInfo(carparkin.getUuid(), ",上传进场纪录失败.");
			try
			{
				if (httpClient != null)
				{
					httpClient.close();
				}
			} catch (IOException localIOException1)
			{
			}
		} finally
		{
			try
			{
				if (null != httpClient)
				{
					httpClient.close();
				}
			} catch (IOException e)
			{
				
			}
		}
	}
	
	/**
	 * 
	 * 方法描述：当车辆入场是把数据同步到云平台 异常
	 * 
	 * @Title: addErrorLogUploadCarInInfo @param @param businessUuid @param @param
	 *         deScript @return void @user Administrator 2016年3月29日 @throws
	 */
	public void addErrorLogUploadCarInInfo(String businessUuid, String deScript)
	{
		Log logInfo = new Log();
		logInfo.setCreaterAt(new Date());
		logInfo.setSummary("上传进场信息异常.");
		logInfo.setDescript(deScript);
		logInfo.setLevel(LogInfoConstan.LEVEL_ALERT);
		logInfo.setSrc(LogInfoConstan.SRC_SYSTEM);
		logInfo.setStatus(LogInfoConstan.STATUS_UNTREATED);
		logInfo.setCls("com.cloud.threads.UploadCarInInfoRunble");
		logInfo.setModule(LogInfoConstan.MODULE_CAR_IN);
		logInfo.setBusinessUuid(businessUuid);
		logServier.addLogInfo(logInfo);
	}
	
	/**
	 * 
	 * 方法描述：上报车辆进出场，信息
	 * 
	 * @Title: uploadReportCarInfo @param @param reportCarInfoVo @return void @user
	 *         Administrator 2016年3月25日 @throws
	 */
	public void uploadReportCarInfo(ReportCarInfoVo reportCarInfoVo)
	{
		// 发送请求
		CloseableHttpClient httpClient = HttpManagerUtil.getInstance()
				.getHttpClient(null);
		try
		{
			
			if (Tools.isEmpty(reportCarInfoVo))
			{
				return;
			}
			// 获取请求路径
			String uri = reportConfigManager.instance().getHost()
					+ reportConfigManager.instance().getCfgValueByKey(
							"reportCarInfo");
			
			HttpPost post = new HttpPost(uri);
			post.setHeader("Content-Type", "application/json;charset=UTF-8");
			post.setConfig(HttpClientUtil.getTimeOutCfg(0));
			String sendData = JsonUtil.getJsonString(reportCarInfoVo);
			StringEntity s = new StringEntity(sendData, "UTF-8");
			post.setEntity(s);
			
			log.debug("上报车牌系统【信息】" + sendData);
			
			CloseableHttpResponse resp = httpClient.execute(post);
			String result = EntityUtils.toString(resp.getEntity(), "UTF-8");
			
			log.debug("上报车牌系统【返回】" + result);
			
			ResultVo resultVo = (ResultVo) JsonUtil.getObjectByJson(result,
					ResultVo.class);
			
			if (resultVo.getResult().equals("success"))
			{
				System.out.println("上报车牌系统成功");
			} else
			{
				System.out.println("上报车牌系统失败.");
				addErrorLogUploadReportCarInfo(reportCarInfoVo.getUuid(),
						"上报车牌系统失败.", reportCarInfoVo.getPassType());
			}
			
		} catch (Throwable t)
		{
			log.error("", t);
			addErrorLogUploadReportCarInfo(reportCarInfoVo.getUuid(),
					"上报车牌系统失败.", reportCarInfoVo.getPassType());
			try
			{
				if (httpClient != null)
				{
					httpClient.close();
				}
			} catch (IOException localIOException1)
			{
			}
		} finally
		{
			try
			{
				if (httpClient != null)
				{
					httpClient.close();
				}
			} catch (IOException localIOException2)
			{
			}
		}
	}
	
	/**
	 * 
	 * 方法描述：上报车辆异常
	 * 
	 * @Title: addErrorLogUploadReportCarInfo @param @param businessUuid @param @param
	 *         deScript @param @param passType @return void @user Administrator
	 *         2016年3月29日 @throws
	 */
	public void addErrorLogUploadReportCarInfo(String businessUuid,
			String deScript, Integer passType)
	{
		Log logInfo = new Log();
		logInfo.setCreaterAt(new Date());
		logInfo.setSummary("上报车辆异常.");
		// 0 进场 1:出场
		logInfo.setDescript(passType.toString());
		logInfo.setLevel(LogInfoConstan.LEVEL_ALERT);
		logInfo.setSrc(LogInfoConstan.SRC_SYSTEM);
		logInfo.setStatus(LogInfoConstan.STATUS_UNTREATED);
		logInfo.setCls("com.cloud.threads.UploadReportCarInfoRunble");
		logInfo.setModule(LogInfoConstan.REPORT_CAR_INFO);
		
		logInfo.setBusinessUuid(businessUuid);
		logServier.addLogInfo(logInfo);
		
	}
	
	/**
	 * 
	 * 方法描述：推送车位数量
	 * 
	 * @Title: pushParkLot @param @return void @user Administrator 2016年3月26日 @throws
	 */
	public void pushParkLot()
	{
		
		try
		{
			TransferVo<ParklotVo> transCar = new TransferVo<ParklotVo>();
			transCar.setEventType("lotCar");
			
			List<ParklotNumber> listNumber = lotNumberMapper
					.queryByPage(new PageInfo<ParklotNumber>());
			
			int carNumber = 200;
			
			if (Tools.isEmpty(listNumber) || listNumber.isEmpty())
			{
				// 插入默认车位数据
				ParklotNumber tmp = new ParklotNumber();
				tmp.setUuid(UUIDGenerateUtil.generate());
				tmp.setNumber(carNumber);
				lotNumberMapper.insertSelective(tmp);
			}
			
			if (!Tools.isEmpty(listNumber) && !listNumber.isEmpty())
			{
				carNumber = listNumber.get(0).getNumber();
			}
			
			// 统计在场车辆
			
			CarParkInExample ex = new CarParkInExample();
			ex.or().andStatusEqualTo(1);
			int exsitNumber = carInMapper.countByCondition(ex);
			
			ParklotVo lotVo = new ParklotVo();
			lotVo.setCarAllLot(carNumber);
			lotVo.setDayIn(exsitNumber);
			
			int freeNumber = carNumber - exsitNumber;
			lotVo.setFreeLot(freeNumber < 0 ? 0 : freeNumber);
			
			transCar.setData(lotVo);
			
			PushManager.instance().pushMessage(transCar);
		} catch (Throwable e)
		{
			log.error("", e);
		}
	}
	
	/**
	 * 
	 * 方法描述：推送前端页面
	 * 
	 * @Title: pushCarInBillInfo @param @param carInpushVo @return void @user
	 *         Administrator 2016年3月26日 @throws
	 */
	public void findPushCarInBillInfo(CarInPushVo carInpushVo)
	{
		try
		{
			// 通过设备编码查询路口数 这些查询需要放入线程里。TODO 张威
			List<Crossing> crossList = crossinService
					.queryCrossingByEquimentNo(carInpushVo.getEuqmentNo());
			
			if (crossList.isEmpty())
			{
				return;
			}
			// 通过路口数查询需要推送多少个岗亭
			List<LocalStation> stationList = crossinService
					.queryStaionsByCrosList(crossList);
			carInpushVo.setStationList(stationList);
			
			if (!Tools.isEmpty(crossList) && !crossList.isEmpty())
			{
				carInpushVo.setRoadName(crossList.get(0).getName());
				carInpushVo.setRoadUuid(crossList.get(0).getUuid());
			}
			
			String stute = carInpushVo.getIsOpenGate().equals("1") ? "已开"
					: "未开";
			// 组装最终显示信息
			carInpushVo.setPageShow(carInpushVo.getCarNoTye()
					+ " ["
					+ carInpushVo.getCarNo()
					+ "]"
					+ (null == carInpushVo.getReptCarIn() ? "" : carInpushVo
							.getReptCarIn()) + ",从  "
					+ carInpushVo.getRoadName() + "驶入!!!  闸机状态[" + stute + "]");
			
			TransferVo<CarInPushVo> trans = new TransferVo<CarInPushVo>();
			trans.setEventType("carIn");
			trans.setData(carInpushVo);
			
			PushManager.instance().pushMessage(trans);
		} catch (Throwable t)
		{
			log.error("", t);
		}
	}
	
	@Override
	public void pushManualOpenCloud(AdminCarInBill adminCarInBill,
			CarInManualOpenVo vo) throws BaseException
	{
		// 1、上传进场手动开闸纪录到云平台
		this.uploadAdminCarInBill(adminCarInBill);
		
		if (!Tools.isEmpty(vo.getCarInInfo()))
		{
			// 2、计费规则副本放入云端
			for (LocalChargeBytimeCopy localChargeBytimeCopy : vo.getListCopy())
			{
				// 计费副本表，放入云平台副本表
				this.setRuleCopy(localChargeBytimeCopy);
			}
			
			// 3、当车辆入场是把数据同步到云平台
			this.uploadCarInInfo(vo.getCarInInfo());
		}
	}
	
	/**
	 * 
	 * 方法描述：上传进场强制
	 * 
	 * @Title: uploadAdminCarInBill @param @param adminCarInBill @return void @user
	 *         Administrator 2016年3月29日 @throws
	 */
	public void uploadAdminCarInBill(AdminCarInBill adminCarInBill)
	{
		// 发送请求
		CloseableHttpClient httpClient = HttpManagerUtil.getInstance()
				.getHttpClient(null);
		try
		{
			
			if (Tools.isEmpty(adminCarInBill))
			{
				return;
			}
			// 获取请求路径
			String uri = CloudConfigManager.instance().getHost()
					+ CloudConfigManager.instance().getCfgValueByKey(
							"sync_admin_car_in_bill");
			
			HttpPost post = new HttpPost(uri);
			post.setHeader("Content-Type", "application/json;charset=UTF-8");
			post.setConfig(HttpClientUtil.getTimeOutCfg(0));
			String sendData = JsonUtil.getJsonString(adminCarInBill);
			StringEntity s = new StringEntity(sendData, "UTF-8");
			post.setEntity(s);
			
			CloseableHttpResponse resp = httpClient.execute(post);
			String result = EntityUtils.toString(resp.getEntity(), "UTF-8");
			
			ResultVo resultVo = (ResultVo) JsonUtil.getObjectByJson(result,
					ResultVo.class);
			
			if (resultVo.getResult().equals("success"))
			{
				System.out.println(adminCarInBill.getCarNo()
						+ "，上传进场手动开闸纪录成功..");
			} else
			{
				System.out.println(adminCarInBill.getCarNo() + ",上传进场手动纪录失败.");
				addErrorLogUpload(adminCarInBill.getUuid(), ",上传进场手动纪录失败.");
			}
			
		} catch (Throwable t)
		{
			log.error("", t);
			addErrorLogUpload(adminCarInBill.getUuid(), ",上传进场手动纪录失败.");
			try
			{
				if (httpClient != null)
				{
					httpClient.close();
				}
			} catch (IOException localIOException1)
			{
			}
		} finally
		{
			try
			{
				if (null != httpClient)
				{
					httpClient.close();
				}
			} catch (IOException e)
			{
				
			}
		}
		
	}
	
	/**
	 * 
	 * 方法描述：上传进场强制异常
	 * 
	 * @Title: addErrorLogUpload @param @param businessUuid @param @param
	 *         deScript @return void @user Administrator 2016年3月29日 @throws
	 */
	public void addErrorLogUpload(String businessUuid, String deScript)
	{
		Log logInfo = new Log();
		logInfo.setCreaterAt(new Date());
		logInfo.setSummary("上传进场强制异常.");
		logInfo.setDescript(deScript);
		logInfo.setLevel(LogInfoConstan.LEVEL_ALERT);
		logInfo.setSrc(LogInfoConstan.SRC_SYSTEM);
		logInfo.setStatus(LogInfoConstan.STATUS_UNTREATED);
		logInfo.setCls("com.cloud.threads.UploadAdminCarInBillRunble");
		logInfo.setModule(LogInfoConstan.MODULE_ADMIN_CARIN_BILL);
		logInfo.setBusinessUuid(businessUuid);
		logService.addLogInfo(logInfo);
	}
	
	@Override
	public void queryCarInByStationPage(CarInAndOutPageInfo<CarParkIn> page)
	{
		// TODO Auto-generated method stub
		List<CarParkIn> reslutList = carInMapper.queryByStationPage(page);
		
		if (!Tools.isEmpty(reslutList))
		{
			List<CarParkIn> roList = new ArrayList<CarParkIn>();
			for (CarParkIn carIn : reslutList)
			{
				CarParkInEx ex = new CarParkInEx();
				BeanUtil.copyProperties(ex, carIn);
				List<Crossing> list = crossionService
						.queryCrossingByEquimentNo(carIn.getEquipment());
				if (!Tools.isEmpty(list) && !list.isEmpty())
				{
					ex.setRoadName(list.get(0).getName());
					ex.setRoadUuid(list.get(0).getUuid());
				}
				
				// 收费类型
				if (!Tools.isEmpty(carIn.getBrand()))
				{
					
					LocalChargeBytime rule = billRuleService
							.findByBrandId(carIn.getBrand());
					ex.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3()
							: "未知");
				}
				roList.add(ex);
			}
			page.setData(roList);
			Integer pageNumber = carInMapper.countAllByStationPage(page);
			page.setTotalRecords(pageNumber);
		}
	}
	
	@Override
	public void queryStayCarInByStation(CarInAndOutPageInfo<CarParkIn> page)
	{
		List<CarParkIn> reslutList = carInMapper
				.queryStayCarInStationPage(page);
		if (!Tools.isEmpty(reslutList))
		{
			List<CarParkIn> roList = new ArrayList<CarParkIn>();
			for (CarParkIn carIn : reslutList)
			{
				CarParkInEx ex = new CarParkInEx();
				BeanUtil.copyProperties(ex, carIn);
				List<Crossing> list = crossionService
						.queryCrossingByEquimentNo(carIn.getEquipment());
				if (!Tools.isEmpty(list) && !list.isEmpty())
				{
					ex.setRoadName(list.get(0).getName());
					ex.setRoadUuid(list.get(0).getUuid());
				}
				
				// 收费类型
				if (!Tools.isEmpty(carIn.getBrand()))
				{
					
					LocalChargeBytime rule = billRuleService
							.findByBrandId(carIn.getBrand());
					ex.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3()
							: "未知");
				}
				
				roList.add(ex);
			}
			page.setData(roList);
			Integer pageNumber = carInMapper.countQueryStayCarInPage(page);
			page.setTotalRecords(pageNumber);
		}
	}
	
	@Override
	public CarOutInfoVo findCarOutInfoByCarOutUuid(String uuid)
	{
		CarOutInfoVo carOutInfoVo = new CarOutInfoVo();
		CarParkOutCopy carParkOutCopy = carOutCopyMapper
				.selectByPrimaryKey(uuid);
		if (!Tools.isEmpty(carParkOutCopy))
		{
			carOutInfoVo.setCarNo(carParkOutCopy.getCarNo());
			carOutInfoVo.setCarOutTime(carParkOutCopy.getCreateTime());
			carOutInfoVo.setCarOutImage(carParkOutCopy.getPic1());
			carOutInfoVo
					.setVersion(Tools.isEmpty(carParkOutCopy.getVersion()) ? 1.0
							: carParkOutCopy.getVersion());
			// 车辆类型，大车小车
			if (!Tools.isEmpty(carParkOutCopy.getType()))
			{
				
				LocalCarType typeInfo = catTypeMapper
						.selectByPrimaryKey(carParkOutCopy.getType());
				if (!Tools.isEmpty(typeInfo))
				{
					carOutInfoVo.setCarTypeName(typeInfo.getCartypeName());
				}
			}
			
			// 收费类型
			if (!Tools.isEmpty(carParkOutCopy.getBrand()))
			{
				
				LocalChargeBytime rule = billRuleService
						.findByBrandId(carParkOutCopy.getBrand());
				carOutInfoVo.setBillType(!Tools.isEmpty(rule) ? rule.getAttr3()
						: "未知");
				
			}
			
			if (!Tools.isEmpty(carParkOutCopy.getCarInUuid()))
			{
				// 查入场
				CarParkInCopy carParkInCopy = carParkInCopyMapper
						.selectByPrimaryKey(carParkOutCopy.getCarInUuid());
				if (!Tools.isEmpty(carParkInCopy))
				{
					carOutInfoVo.setCarInTime(carParkInCopy.getCreateTime());
					carOutInfoVo.setCarInImage(carParkInCopy.getPic1());
					if (!Tools.isEmpty(carParkInCopy.getEquipment()))
					{
						// 查入场路口
						List<Crossing> crossList = crossinService
								.queryCrossingByEquimentNo(carParkInCopy
										.getEquipment());
						if (!Tools.isEmpty(crossList))
						{
							carOutInfoVo.setCarInStationName(crossList.get(0)
									.getName());
						}
					}
					carOutInfoVo.setStayTime(carParkOutCopy.getCreateTime()
							.getTime()
							- carParkInCopy.getCreateTime().getTime());
				}
				List<LocalPayBill> localPayBills = localPayBillMapper
						.queryAllBill(carParkOutCopy.getCarInUuid());
				List<CarOutPayBillVo> carOutPayBillVos = new ArrayList<CarOutPayBillVo>();
				Double totalPrice = 0.0;
				for (LocalPayBill localPayBill : localPayBills)
				{
					CarOutPayBillVo carOutPayBillVo = new CarOutPayBillVo();
					carOutPayBillVo.setPayTime(localPayBill.getPayTime());
					carOutPayBillVo.setPayType(localPayBill.getPayType());
					// 已支付
					carOutPayBillVo.setCashMoney(localPayBill.getPrice());
					if (PayTypeConstans.MONEY_TYPE.equals(localPayBill
							.getPayType()))
					{
						// 现金
						carOutPayBillVo.setMoney(localPayBill.getActualPrice());
						// 纸质抵扣卷
						carOutPayBillVo.setPaperPreferential(localPayBill
								.getPrice() - localPayBill.getActualPrice());
					} else if (PayTypeConstans.MOBILE_TYPE.equals(localPayBill
							.getPayType()))
					{
						
					} else if (PayTypeConstans.AUTO_PAY_TYPE
							.equals(localPayBill.getPayType()))
					{
						
					} else if (PayTypeConstans.MENMBER_TYPE.equals(localPayBill
							.getPayType()))
					{
						
					} else if (PayTypeConstans.FREE_TYPE.equals(localPayBill
							.getPayType()))
					{
						
					}
					carOutPayBillVos.add(carOutPayBillVo);
					totalPrice += localPayBill.getPrice();
				}
				carOutInfoVo.setCarOutPayBillVos(carOutPayBillVos);
				carOutInfoVo
						.setTotalMoney(!Tools.isEmpty(totalPrice) ? totalPrice
								: 0d);
			}
			if (!Tools.isEmpty(carParkOutCopy.getEquipment()))
			{
				// 查出场路口
				List<Crossing> crossList = crossinService
						.queryCrossingByEquimentNo(carParkOutCopy
								.getEquipment());
				if (!Tools.isEmpty(crossList))
				{
					carOutInfoVo.setCarOutStationName(crossList.get(0)
							.getName());
				}
			}
		}
		if (Tools.isEmpty(carOutInfoVo.getTotalMoney()))
		{
			carOutInfoVo.setTotalMoney(0d);
		}
		return carOutInfoVo;
	}
	
	/**
	 * 
	 * 方法描述：进场控制，车位满时临时车是否开闸 @Title: localParkSpaceFlag @param @return @return
	 * boolean @user Administrator 2016年4月20日 @throws
	 */
	public boolean localParkSpaceFlag(String carNoType)
	{
		Boolean flag = this.panCarNoType(carNoType);
		try
		{
			if (!flag)
			{
				int carNumber = 200;
				// 查询总共的车位数
				List<ParklotNumber> listNumber = lotNumberMapper
						.queryByPage(new PageInfo<ParklotNumber>());
				
				if (Tools.isEmpty(listNumber) || listNumber.isEmpty())
				{
					// 插入默认车位数据
					ParklotNumber tmp = new ParklotNumber();
					tmp.setUuid(UUIDGenerateUtil.generate());
					tmp.setNumber(carNumber);
					lotNumberMapper.insertSelective(tmp);
				}
				
				if (!Tools.isEmpty(listNumber) && !listNumber.isEmpty())
				{
					carNumber = listNumber.get(0).getNumber();
				}
				
				// 统计在场车辆
				CarParkInExample ex = new CarParkInExample();
				ex.or().andStatusEqualTo(1);
				int exsitNumber = carInMapper.countByCondition(ex);
				
				// 车位已满时
				if (carNumber == exsitNumber)
				{
					return false;
				}
			}
		} catch (Exception e)
		{
			// TODO: handle exception
			return true;
		}
		return flag;
	}
	
	@Override
	public void inserCarInRepertory(CarParkInOverVo carInVo)
	{
		if (!Tools.isEmpty(carInVo.getCarparkIn().getCarNo().trim())
				&& !"无效车牌".equalsIgnoreCase(carInVo.getCarparkIn().getCarNo()
						.trim()))
		{
			LocalCarInRepertoryExample carInEx = new LocalCarInRepertoryExample();
			carInEx.or().andCarNoEqualTo(
					carInVo.getCarparkIn().getCarNo().trim());
			List<LocalCarInRepertory> localCarInRepertories = localCarInRepertoryMapper
					.selectByCondition(carInEx);
			if (!Tools.isEmpty(localCarInRepertories))
			{
				for (LocalCarInRepertory localCarInRepertory : localCarInRepertories)
				{
					localCarInRepertoryMapper
							.deleteByPrimaryKey(localCarInRepertory.getUuid());
				}
			}
		}
		LocalCarInRepertory localCarInRepertory = new LocalCarInRepertory();
		localCarInRepertory.setUuid(UUIDGenerateUtil.generate());
		localCarInRepertory.setCarInUuid(carInVo.getCarparkIn().getUuid());
		localCarInRepertory
				.setCarInTime(carInVo.getCarparkIn().getCreateTime());
		localCarInRepertory.setCarNo(carInVo.getCarparkIn().getCarNo().trim());
		localCarInRepertory.setCarTypeUuid(carInVo.getCarparkIn().getCarType());
		
		payTyeAndOpenType(carInVo.getCarparkIn().getCarNo().trim(),
				localCarInRepertory);
		
		if (Tools.isEmpty(localCarInRepertory.getCarTypeUuid()))
		{
			localCarInRepertory.setCarTypeUuid(ConfigManager.instance()
					.getDefaultCarType());
		}
		LocalChargeBytimeExample ex = new LocalChargeBytimeExample();
		ex.or().andAttr4EqualTo(
				!Tools.isEmpty(carInVo.getCarparkIn().getBrand()) ? carInVo
						.getCarparkIn().getBrand() : "102");
		
		/* ex.or().andCarTypeEqualTo(localCarInRepertory.getCarTypeUuid()); */
		List<LocalChargeBytime> list = localChargeBytimeMapper
				.selectByCondition(ex);
		localCarInRepertory.setAttr(!Tools.isEmpty(carInVo.getCarparkIn()
				.getBrand()) ? carInVo.getCarparkIn().getBrand() : "102");
		// 如果计费规则找不到，就用临时默认规则
		if (Tools.isEmpty(list))
		{
			LocalChargeBytimeExample exx = new LocalChargeBytimeExample();
			exx.or().andAttr4EqualTo("102");
			list = localChargeBytimeMapper.selectByCondition(exx);
			localCarInRepertory.setAttr("102");
		}
		String chargeUuids = "";
		for (LocalChargeBytime localChargeBytime : list)
		{
			chargeUuids += localChargeBytime.getChargeBytimeUuid() + ",";
		}
		localCarInRepertory.setChargeUuid(Tools.isEmpty(chargeUuids) ? null
				: chargeUuids.substring(0, chargeUuids.length() - 1));
		localCarInRepertoryMapper.insertSelective(localCarInRepertory);
	}
	
	@Override
	public void updateCarInRepertory(CarParkIn carInInfo)
	{
		LocalCarInRepertoryExample carInEx = new LocalCarInRepertoryExample();
		carInEx.or().andCarInUuidEqualTo(carInInfo.getUuid());
		List<LocalCarInRepertory> localCarInRepertories = localCarInRepertoryMapper
				.selectByCondition(carInEx);
		if (!Tools.isEmpty(localCarInRepertories))
		{
			for (LocalCarInRepertory localCarInRepertory : localCarInRepertories)
			{
				localCarInRepertory.setCarNo(carInInfo.getCarNo().trim());
				localCarInRepertory.setCarInTime(carInInfo.getCreateTime());
				this.payTyeAndOpenType(carInInfo.getCarNo().trim(),
						localCarInRepertory);
				localCarInRepertoryMapper
						.updateByPrimaryKeySelective(localCarInRepertory);
			}
		}
	}
	
	/**
	 * 方法描述：查询车辆类型和收费类型以及到期时间 @Title: payTyeAndOpenType @param @param carInVo @param @param
	 * localCarInRepertory @return void @user pichunhan 2016年4月22日 @throws
	 */
	private void payTyeAndOpenType(String carNo,
			LocalCarInRepertory localCarInRepertory)
	{
		localCarInRepertory.setOpenType(CommonContains.OPEN_TYPE_FALSE);
		localCarInRepertory.setPayType(CommonContains.TEMP_LIST);
		LocalBlackList lbl = localBlackListService.queryBlackListByCarNo(carNo);
		if (!Tools.isEmpty(lbl))
		{
			if (CommonContains.BLACK_LIST.equals(lbl.getType()))
			{
				localCarInRepertory.setOpenType(CommonContains.OPEN_TYPE_BLACK);
				localCarInRepertory.setPayType(CommonContains.BLACK_LIST);
			} else if (CommonContains.WHITE_LIST.equals(lbl.getType()))
			{
				localCarInRepertory.setOpenType(CommonContains.OPEN_TYPE_TRUE);
				localCarInRepertory.setPayType(CommonContains.WHITE_LIST);
			}
			localCarInRepertory.setExpireTime(lbl.getEndTime());
		} else
		{
			FreeCar freecar = freeCarService.queryFreeCarNo(carNo);
			if (!Tools.isEmpty(freecar))
			{
				localCarInRepertory.setOpenType(CommonContains.OPEN_TYPE_TRUE);
				localCarInRepertory.setPayType(CommonContains.FREE_LIST);
				localCarInRepertory.setExpireTime(freecar.getTimeInterval());
			} else
			{
				List<LocalMember> parkwellMemberCards = parkwellMemberService
						.findCarNoIsMemberInPark(carNo.trim(),
								new Date(System.currentTimeMillis()));
				if (!Tools.isEmpty(parkwellMemberCards))
				{
					localCarInRepertory
							.setOpenType(CommonContains.OPEN_TYPE_TRUE);
					localCarInRepertory.setPayType(CommonContains.MEMBER_LIST);
					localCarInRepertory.setExpireTime(parkwellMemberCards
							.get(0).getEndTime());
					localCarInRepertory.setStartTime(parkwellMemberCards.get(0)
							.getStartTime());
				} else
				{
					// 查询平台会员
					IntegrationExample inEx = new IntegrationExample();
					inEx.or().andCarNoEqualTo(carNo.trim());
					List<Integration> intList = interationMapper
							.selectByCondition(inEx);
					if (!Tools.isEmpty(intList))
					{
						localCarInRepertory
								.setOpenType(CommonContains.OPEN_TYPE_FALSE);
						localCarInRepertory
								.setPayType(CommonContains.PLATFORM_LIST);
					}
				}
			}
		}
		
	}
	
	@Override
	public void convertCarIn()
	{
		CarParkInExample carInEx = new CarParkInExample();
		carInEx.or().andStatusEqualTo(1);
		List<CarParkIn> list = carInMapper.selectByCondition(carInEx);
		for (CarParkIn carParkIn : list)
		{
			CarParkInOverVo carInVo = new CarParkInOverVo();
			carInVo.setCarparkIn(carParkIn);
			this.inserCarInRepertory(carInVo);
		}
	}
	
	@Override
	public LocalChargeBytimeType getFirCarTypeNo(String type)
	{
		// TODO Auto-generated method stub
		LocalChargeBytimeType lct = null;
		if (Tools.isEmpty(type))
		{
			return lct;
		}
		
		if (!Tools.isEmpty(type))
		{
			LocalChargeBytimeTypeExample condtion = new LocalChargeBytimeTypeExample();
			condtion.or().andTypeEqualTo(type);
			List<LocalChargeBytimeType> lbt = localChargeByTimeTypeService
					.selectByCondition(condtion);
			if (!Tools.isEmpty(lbt))
			{
				lct = lbt.get(0);
			}
		}
		return lct;
	}
	
	@Override
	public Screen queryScreenByCamelDeviceId(String cameraNo)
	{
		// TODO Auto-generated method stub
		Screen screen = localScreenMapper.queryScreenByCamelDeviceId(cameraNo);
		return screen;
	}
	
	@Override
	public void deleteCarInAndRepertory()
	{
		// TODO Auto-generated method stub
		// 进场表数据存在，但结果表找不到
		/* carInMapper.deleteCarIn(); */
		
		// 结果表的数据存在，但是进场表却找不到。。即删除 结果表数据
		localCarInRepertoryMapper.deleteRepertory();
	}
	
	@Override
	public void updateCarNo(CarParkIn carParkIn) throws BaseException
	{
		try
		{
			// TODO Auto-generated method stub
			if (Tools.isEmpty(carParkIn.getCarNo()))
			{
				throw new BaseException("50000-00001-00068");
			}
			if ("无效车牌".equalsIgnoreCase(carParkIn.getCarNo()))
			{
				throw new BaseException("50000-00001-00069");
			}
			CarParkInExample condtion = new CarParkInExample();
			condtion.or().andCarNoEqualTo(carParkIn.getCarNo());
			List<CarParkIn> list = carInMapper.selectByCondition(condtion);
			if (!Tools.isEmpty(list) && list.size() != 0)
			{
				throw new BaseException("50000-00001-00070");
			}
			LocalChargeBytimeType ltc = this.makeCarNoType(carParkIn);
			
			CarParkIn cc = carInMapper.selectByPrimaryKey(carParkIn.getUuid());
			cc.setCarNo(carParkIn.getCarNo());
			cc.setBrand(!Tools.isEmpty(ltc) ? ltc.getType() : "102");
			// cc.setCarType(ConfigManager.instance().getDefaultCarType());
			carInMapper.updateByPrimaryKeySelective(cc);
			
			LocalCarInRepertoryExample creper = new LocalCarInRepertoryExample();
			creper.or().andCarInUuidEqualTo(cc.getUuid());
			LocalCarInRepertory ll = localCarInRepertoryMapper
					.selectByCondition(creper).get(0);
			
			LocalChargeBytimeExample ex = new LocalChargeBytimeExample();
			ex.or().andAttr4EqualTo(
					!Tools.isEmpty(cc.getBrand()) ? cc.getBrand() : "102");
			List<LocalChargeBytime> listtt = localChargeBytimeMapper
					.selectByCondition(ex);
			ll.setAttr(!Tools.isEmpty(cc.getBrand()) ? cc.getBrand() : "102");
			// 如果计费规则找不到，就用临时默认规则
			if (Tools.isEmpty(listtt))
			{
				LocalChargeBytimeExample exx = new LocalChargeBytimeExample();
				exx.or().andAttr4EqualTo("102");
				listtt = localChargeBytimeMapper.selectByCondition(exx);
				ll.setAttr("102");
			}
			ll.setChargeUuid(listtt.get(0).getChargeBytimeUuid());
			ll.setCarNo(cc.getCarNo());
			ll.setExpireTime(!Tools.isEmpty(ltc)
					&& !Tools.isEmpty(ltc.getExpireTime()) ? ltc
					.getExpireTime() : null);
			ll.setStartTime(!Tools.isEmpty(ltc)
					&& !Tools.isEmpty(ltc.getStartTime()) ? ltc.getStartTime()
					: null);
			localCarInRepertoryMapper.updateByPrimaryKeySelective(ll);
		} catch (Throwable t)
		{
			// TODO: handle exception
			throw new BaseException(t.getMessage(), t);
		}
	}
	
	//TODO hjp 临时方法,只在容器初始化时自动将数据库所有数据建立索引
	@PostConstruct
	private void batchIndexCarInAndOutHisData()
	{
		PageInfo<CarParkInCopy> page = new PageInfo<CarParkInCopy>();
		page.setCurrentPage(1);
		page.setPageSize(Integer.MAX_VALUE);
		List<CarParkInCopy> carInList = carParkInCopyMapper.queryByPage(page);
		IndexWriter writer = IndexUtil.getIndexWriter(LuceneConstants.ROOT_PATH + 
				CarParkInCopy.class.getSimpleName(), true);
		List<Map<FieldEnum, Object>> list = new ArrayList<Map<FieldEnum,Object>>();
		for(CarParkInCopy  carInRepertory: carInList)
        {
        	if(!Tools.isEmpty(carInRepertory.getCarNo()) && !Tools.isEmpty(carInRepertory.getUuid())){
				Map<FieldEnum, Object> map = new HashMap<FieldEnum, Object>();
				map.put(FieldEnum.CONTENTS, carInRepertory.getCarNo());
				map.put(FieldEnum.MODIFY_TIME, carInRepertory.getCreateTime());
				map.put(FieldEnum.STRING_FIELD, carInRepertory.getCarNo());
				list.add(map);
			}
        }
		IndexUtil.indexDoc(writer, list);
		IndexUtil.closeWriter();
		
		PageInfo<CarParkOutCopy> page1 = new PageInfo<CarParkOutCopy>();
		page1.setCurrentPage(1);
		page1.setPageSize(Integer.MAX_VALUE);
		List<CarParkOutCopy> carInL1ist = carOutCopyMapper.queryByPage(page1);
		IndexWriter wri1ter = IndexUtil.getIndexWriter(LuceneConstants.ROOT_PATH + 
				CarParkOutCopy.class.getSimpleName(), true);
		List<Map<FieldEnum, Object>> li1st = new ArrayList<Map<FieldEnum,Object>>();
		for(CarParkOutCopy  carInRepertory: carInL1ist)
        {
        	if(!Tools.isEmpty(carInRepertory.getCarNo()) && !Tools.isEmpty(carInRepertory.getUuid())){
				Map<FieldEnum, Object> map = new HashMap<FieldEnum, Object>();
				map.put(FieldEnum.CONTENTS, carInRepertory.getCarNo());
				map.put(FieldEnum.MODIFY_TIME, carInRepertory.getCreateTime());
				map.put(FieldEnum.STRING_FIELD, carInRepertory.getCarNo());
				li1st.add(map);
			}
        }
		IndexUtil.indexDoc(wri1ter, li1st);
		IndexUtil.closeWriter();

		PageInfo<LocalPayBill> page2 = new PageInfo<LocalPayBill>();
		page2.setCurrentPage(1);
		page2.setPageSize(Integer.MAX_VALUE);
		List<LocalPayBill> carInL1is1t = localPayBillMapper.queryByPage(page2);
		IndexWriter wri1t1er = IndexUtil.getIndexWriter(LuceneConstants.ROOT_PATH + 
				LocalPayBill.class.getSimpleName(), true);
		List<Map<FieldEnum, Object>> li11st = new ArrayList<Map<FieldEnum,Object>>();
		for(LocalPayBill  carInRepertory: carInL1is1t)
        {
        	if(!Tools.isEmpty(carInRepertory.getCarNo()) && !Tools.isEmpty(carInRepertory.getCarOutUuid())){
				Map<FieldEnum, Object> map = new HashMap<FieldEnum, Object>();
				map.put(FieldEnum.CONTENTS, carInRepertory.getCarNo());
				map.put(FieldEnum.MODIFY_TIME, carInRepertory.getPayTime());
				map.put(FieldEnum.STRING_FIELD, carInRepertory.getCarNo());
				li11st.add(map);
			}
        }
		IndexUtil.indexDoc(wri1t1er, li11st);
		IndexUtil.closeWriter();
	}
}
